mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
dummy -> stub. Also minor help message update.
This commit is contained in:
parent
dead264798
commit
e25475e7a1
3 changed files with 34 additions and 38 deletions
|
@ -44,7 +44,7 @@ pub const CMD_VERSION: &str = "version";
|
|||
pub const CMD_FORMAT: &str = "format";
|
||||
pub const CMD_TEST: &str = "test";
|
||||
pub const CMD_GLUE: &str = "glue";
|
||||
pub const CMD_GEN_DUMMY_LIB: &str = "gen-dummy-lib";
|
||||
pub const CMD_GEN_STUB_LIB: &str = "gen-stub-lib";
|
||||
|
||||
pub const FLAG_DEBUG: &str = "debug";
|
||||
pub const FLAG_DEV: &str = "dev";
|
||||
|
@ -277,8 +277,8 @@ pub fn build_app<'a>() -> Command<'a> {
|
|||
.required(true)
|
||||
)
|
||||
)
|
||||
.subcommand(Command::new(CMD_GEN_DUMMY_LIB)
|
||||
.about("Generate a dummy shared library that can be used for linking a platform binary")
|
||||
.subcommand(Command::new(CMD_GEN_STUB_LIB)
|
||||
.about("Generate a stubbed shared library that can be used for linking a platform binary.\nThe stubbed library has prototypes, but no function bodies.\n\nNote: This command will be removed in favor of just using `roc build` once all platforms support the surgical linker")
|
||||
.arg(
|
||||
Arg::new(ROC_FILE)
|
||||
.help("The .roc file for an app using the platform")
|
||||
|
|
|
@ -2,7 +2,7 @@ use roc_build::link::LinkType;
|
|||
use roc_cli::build::check_file;
|
||||
use roc_cli::{
|
||||
build_app, format, test, BuildConfig, FormatMode, Target, CMD_BUILD, CMD_CHECK, CMD_DEV,
|
||||
CMD_DOCS, CMD_EDIT, CMD_FORMAT, CMD_GEN_DUMMY_LIB, CMD_GLUE, CMD_REPL, CMD_RUN, CMD_TEST,
|
||||
CMD_DOCS, CMD_EDIT, CMD_FORMAT, CMD_GEN_STUB_LIB, CMD_GLUE, CMD_REPL, CMD_RUN, CMD_TEST,
|
||||
CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_LIB, FLAG_NO_LINK, FLAG_TARGET, FLAG_TIME,
|
||||
GLUE_FILE, ROC_FILE,
|
||||
};
|
||||
|
@ -93,11 +93,11 @@ fn main() -> io::Result<()> {
|
|||
Ok(1)
|
||||
}
|
||||
}
|
||||
Some((CMD_GEN_DUMMY_LIB, matches)) => {
|
||||
Some((CMD_GEN_STUB_LIB, matches)) => {
|
||||
let input_path = Path::new(matches.value_of_os(ROC_FILE).unwrap());
|
||||
let target: Target = matches.value_of_t(FLAG_TARGET).unwrap_or_default();
|
||||
|
||||
roc_linker::generate_dummy_lib(input_path, &target.to_triple())
|
||||
roc_linker::generate_stub_lib(input_path, &target.to_triple())
|
||||
}
|
||||
Some((CMD_BUILD, matches)) => {
|
||||
let target: Target = matches.value_of_t(FLAG_TARGET).unwrap_or_default();
|
||||
|
|
|
@ -56,7 +56,7 @@ pub fn build_and_preprocess_host(
|
|||
exposed_to_host: Vec<String>,
|
||||
exported_closure_types: Vec<String>,
|
||||
) {
|
||||
let dummy_lib = if let target_lexicon::OperatingSystem::Windows = target.operating_system {
|
||||
let stub_lib = if let target_lexicon::OperatingSystem::Windows = target.operating_system {
|
||||
host_input_path.with_file_name("libapp.dll")
|
||||
} else {
|
||||
host_input_path.with_file_name("libapp.so")
|
||||
|
@ -68,9 +68,9 @@ pub fn build_and_preprocess_host(
|
|||
host_input_path.with_file_name("dynhost")
|
||||
};
|
||||
|
||||
let dummy_dll_symbols = make_dummy_dll_symbols(exposed_to_host, exported_closure_types);
|
||||
generate_dynamic_lib(target, &dummy_dll_symbols, &dummy_lib);
|
||||
rebuild_host(opt_level, target, host_input_path, Some(&dummy_lib));
|
||||
let stub_dll_symbols = make_stub_dll_symbols(exposed_to_host, exported_closure_types);
|
||||
generate_dynamic_lib(target, &stub_dll_symbols, &stub_lib);
|
||||
rebuild_host(opt_level, target, host_input_path, Some(&stub_lib));
|
||||
let metadata = host_input_path.with_file_name("metadata");
|
||||
// let prehost = host_input_path.with_file_name("preprocessedhost");
|
||||
|
||||
|
@ -79,8 +79,8 @@ pub fn build_and_preprocess_host(
|
|||
&dynhost,
|
||||
&metadata,
|
||||
preprocessed_host_path,
|
||||
&dummy_lib,
|
||||
&dummy_dll_symbols,
|
||||
&stub_lib,
|
||||
&stub_dll_symbols,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
|
@ -96,8 +96,8 @@ pub fn link_preprocessed_host(
|
|||
surgery(roc_app_bytes, &metadata, binary_path, false, false, target)
|
||||
}
|
||||
|
||||
// Exposed function to load a platform file and generate a dummy lib for it.
|
||||
pub fn generate_dummy_lib(input_path: &Path, triple: &Triple) -> std::io::Result<i32> {
|
||||
// Exposed function to load a platform file and generate a stub lib for it.
|
||||
pub fn generate_stub_lib(input_path: &Path, triple: &Triple) -> std::io::Result<i32> {
|
||||
// Note: this should theoretically just be able to load the host, I think.
|
||||
// Instead, I am loading an entire app because that was simpler and had example code.
|
||||
// If this was expected to stay around for the the long term, we should change it.
|
||||
|
@ -144,21 +144,21 @@ pub fn generate_dummy_lib(input_path: &Path, triple: &Triple) -> std::io::Result
|
|||
.parent()
|
||||
.unwrap()
|
||||
.join(platform_path);
|
||||
let dummy_lib = if let target_lexicon::OperatingSystem::Windows = triple.operating_system {
|
||||
let stub_lib = if let target_lexicon::OperatingSystem::Windows = triple.operating_system {
|
||||
platform_path.with_file_name("libapp.obj")
|
||||
} else {
|
||||
platform_path.with_file_name("libapp.so")
|
||||
};
|
||||
|
||||
let dummy_dll_symbols = make_dummy_dll_symbols(exposed_to_host, exported_closure_types);
|
||||
generate_dynamic_lib(triple, &dummy_dll_symbols, &dummy_lib);
|
||||
let stub_dll_symbols = make_stub_dll_symbols(exposed_to_host, exported_closure_types);
|
||||
generate_dynamic_lib(triple, &stub_dll_symbols, &stub_lib);
|
||||
} else {
|
||||
unreachable!();
|
||||
};
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
fn make_dummy_dll_symbols(
|
||||
fn make_stub_dll_symbols(
|
||||
exposed_to_host: Vec<String>,
|
||||
exported_closure_types: Vec<String>,
|
||||
) -> Vec<String> {
|
||||
|
@ -187,23 +187,23 @@ fn make_dummy_dll_symbols(
|
|||
custom_names
|
||||
}
|
||||
|
||||
fn generate_dynamic_lib(target: &Triple, dummy_dll_symbols: &[String], dummy_lib_path: &Path) {
|
||||
if !dummy_lib_is_up_to_date(target, dummy_lib_path, dummy_dll_symbols) {
|
||||
let bytes = crate::generate_dylib::generate(target, dummy_dll_symbols)
|
||||
fn generate_dynamic_lib(target: &Triple, stub_dll_symbols: &[String], stub_lib_path: &Path) {
|
||||
if !stub_lib_is_up_to_date(target, stub_lib_path, stub_dll_symbols) {
|
||||
let bytes = crate::generate_dylib::generate(target, stub_dll_symbols)
|
||||
.unwrap_or_else(|e| internal_error!("{e}"));
|
||||
|
||||
std::fs::write(dummy_lib_path, &bytes).unwrap_or_else(|e| internal_error!("{e}"));
|
||||
std::fs::write(stub_lib_path, &bytes).unwrap_or_else(|e| internal_error!("{e}"));
|
||||
|
||||
if let target_lexicon::OperatingSystem::Windows = target.operating_system {
|
||||
generate_import_library(dummy_lib_path, dummy_dll_symbols);
|
||||
generate_import_library(stub_lib_path, stub_dll_symbols);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_import_library(dummy_lib_path: &Path, custom_names: &[String]) {
|
||||
fn generate_import_library(stub_lib_path: &Path, custom_names: &[String]) {
|
||||
let def_file_content = generate_def_file(custom_names).expect("write to string never fails");
|
||||
|
||||
let mut def_path = dummy_lib_path.to_owned();
|
||||
let mut def_path = stub_lib_path.to_owned();
|
||||
def_path.set_extension("def");
|
||||
|
||||
std::fs::write(def_path, def_file_content.as_bytes())
|
||||
|
@ -225,7 +225,7 @@ fn generate_import_library(dummy_lib_path: &Path, custom_names: &[String]) {
|
|||
//
|
||||
// > https://github.com/messense/implib-rs
|
||||
let output = std::process::Command::new(&zig)
|
||||
.current_dir(dummy_lib_path.parent().unwrap())
|
||||
.current_dir(stub_lib_path.parent().unwrap())
|
||||
.args(&[
|
||||
"dlltool",
|
||||
"-d",
|
||||
|
@ -290,20 +290,16 @@ fn object_matches_target<'a>(target: &Triple, object: &object::File<'a, &'a [u8]
|
|||
}
|
||||
}
|
||||
|
||||
/// Checks whether the dummy `.dll/.so` is up to date, in other words that it exports exactly the
|
||||
/// Checks whether the stub `.dll/.so` is up to date, in other words that it exports exactly the
|
||||
/// symbols that it is supposed to export, and is built for the right target. If this is the case,
|
||||
/// we can skip rebuildingthe dummy lib.
|
||||
fn dummy_lib_is_up_to_date(
|
||||
target: &Triple,
|
||||
dummy_lib_path: &Path,
|
||||
custom_names: &[String],
|
||||
) -> bool {
|
||||
if !std::path::Path::exists(dummy_lib_path) {
|
||||
/// we can skip rebuildingthe stub lib.
|
||||
fn stub_lib_is_up_to_date(target: &Triple, stub_lib_path: &Path, custom_names: &[String]) -> bool {
|
||||
if !std::path::Path::exists(stub_lib_path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let dummy_lib = open_mmap(dummy_lib_path);
|
||||
let object = object::File::parse(&*dummy_lib).unwrap();
|
||||
let stub_lib = open_mmap(stub_lib_path);
|
||||
let object = object::File::parse(&*stub_lib).unwrap();
|
||||
|
||||
// the user may have been cross-compiling.
|
||||
// The dynhost on disk must match our current target
|
||||
|
@ -329,7 +325,7 @@ fn preprocess(
|
|||
metadata_path: &Path,
|
||||
preprocessed_path: &Path,
|
||||
shared_lib: &Path,
|
||||
dummy_dll_symbols: &[String],
|
||||
stub_dll_symbols: &[String],
|
||||
verbose: bool,
|
||||
time: bool,
|
||||
) {
|
||||
|
@ -371,7 +367,7 @@ fn preprocess(
|
|||
host_exe_path,
|
||||
metadata_path,
|
||||
preprocessed_path,
|
||||
dummy_dll_symbols,
|
||||
stub_dll_symbols,
|
||||
verbose,
|
||||
time,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue