dummy -> stub. Also minor help message update.

This commit is contained in:
Brendan Hansknecht 2022-10-24 14:02:31 -07:00
parent dead264798
commit e25475e7a1
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
3 changed files with 34 additions and 38 deletions

View file

@ -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,
)