fix plumbing for roc_glue

This commit is contained in:
Luke Boswell 2024-08-18 15:05:57 +10:00
parent ac78d393f9
commit 861222078e
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
3 changed files with 76 additions and 68 deletions

View file

@ -433,12 +433,20 @@ fn gen_from_mono_module_dev<'a>(
) -> GenFromMono<'a> { ) -> GenFromMono<'a> {
match (preprocessed_host_path, target.architecture()) { match (preprocessed_host_path, target.architecture()) {
(PrebuiltHost::Additive(host_path), Architecture::Wasm32) => { (PrebuiltHost::Additive(host_path), Architecture::Wasm32) => {
#[cfg(feature = "target-wasm32")]
{
gen_from_mono_module_dev_wasm32(arena, loaded, host_path, wasm_dev_stack_bytes) gen_from_mono_module_dev_wasm32(arena, loaded, host_path, wasm_dev_stack_bytes)
} }
(PrebuiltHost::None, Architecture::Wasm32) => {
todo!("Cannot compile wasm32 without a host on the dev compiler backend") #[cfg(not(feature = "target-wasm32"))]
{
internal_error!();
} }
(PrebuiltHost::Legacy(host_path), Architecture::Wasm32) => todo!( }
(PrebuiltHost::None, Architecture::Wasm32) => {
internal_error!("Cannot compile wasm32 without a host on the dev compiler backend")
}
(PrebuiltHost::Legacy(host_path), Architecture::Wasm32) => internal_error!(
"Unsupported host files found for use with wasm32 dev compiler backend\n {}", "Unsupported host files found for use with wasm32 dev compiler backend\n {}",
host_path.display() host_path.display()
), ),
@ -447,18 +455,26 @@ fn gen_from_mono_module_dev<'a>(
preprocessed_host, .. preprocessed_host, ..
}), }),
Architecture::Wasm32, Architecture::Wasm32,
) => todo!( ) => internal_error!(
"Unsupported host files found for use with wasm32 dev compiler backend\n {}", "Unsupported host files found for use with wasm32 dev compiler backend\n {}",
preprocessed_host.display() preprocessed_host.display()
), ),
(_, Architecture::X86_64 | Architecture::Aarch64) => { (_, Architecture::X86_64 | Architecture::Aarch64) => {
#[cfg(not(feature = "target-wasm32"))]
{
gen_from_mono_module_dev_assembly(arena, loaded, target, backend_mode) gen_from_mono_module_dev_assembly(arena, loaded, target, backend_mode)
} }
#[cfg(feature = "target-wasm32")]
{
internal_error!()
}
}
(_, Architecture::Aarch32) => { (_, Architecture::Aarch32) => {
todo!("Dev compiler backend does not support 32 bit ARM architectures") internal_error!("Dev compiler backend does not support 32 bit ARM architectures")
} }
(_, Architecture::X86_32) => { (_, Architecture::X86_32) => {
todo!("Dev compiler backend does not support 32 bit x86 architectures") internal_error!("Dev compiler backend does not support 32 bit x86 architectures")
} }
} }
} }
@ -930,13 +946,11 @@ fn build_loaded_file<'a>(
)); ));
std::process::exit(1); std::process::exit(1);
} }
(Err(legacy_paths), Err(surgical_paths), true, LinkType::Dylib) => { (Err(..), Err(..), true, LinkType::Dylib) => {
report_rebuilding_missing_host(&format!("{legacy_paths}\n {surgical_paths}"));
eprintln!("You asked me to build the host, but I don't know how to rebuild a host for a dynamic library."); eprintln!("You asked me to build the host, but I don't know how to rebuild a host for a dynamic library.");
std::process::exit(1); std::process::exit(1);
} }
(Err(legacy_paths), Err(surgical_paths), true, LinkType::None) => { (Err(..), Err(..), true, LinkType::None) => {
report_rebuilding_missing_host(&format!("{legacy_paths}\n {surgical_paths}"));
eprintln!("You asked me to build the host, but I don't know how to rebuild a host for an unlinked object."); eprintln!("You asked me to build the host, but I don't know how to rebuild a host for an unlinked object.");
std::process::exit(1); std::process::exit(1);
} }
@ -1055,7 +1069,8 @@ fn build_loaded_file<'a>(
host_path.push_str(&p.to_string_lossy()); host_path.push_str(&p.to_string_lossy());
inputs.push(&host_path); inputs.push(&host_path);
} else { } else {
panic!("incompatible host path: {:?}", built_host_path); // we may be compiling a Dylib, which doesn't have a host
// for example, we could be generating glue using `roc glue`
} }
let builtins_host_tempfile = roc_bitcode::host_tempfile() let builtins_host_tempfile = roc_bitcode::host_tempfile()

View file

@ -77,9 +77,9 @@ pub fn generate(
let tempdir_res = tempfile::tempdir(); let tempdir_res = tempfile::tempdir();
// TODO confirm these are the correct parameters to pass down. // we don't need a host for glue, we will generate a dylib
// are we building a host here in glue generation? // that will be loaded by the roc compiler/cli
let build_host = true; let build_host = false;
let suppress_build_host_warning = true; let suppress_build_host_warning = true;
let res_binary_path = match tempdir_res { let res_binary_path = match tempdir_res {

View file

@ -45,7 +45,7 @@ mod glue_cli_run {
fn $test_name() { fn $test_name() {
let dir = fixtures_dir($fixture_dir); let dir = fixtures_dir($fixture_dir);
// generate_glue_for(&dir, std::iter::empty()); generate_glue_for(&dir, std::iter::empty());
fn validate<'a, I: IntoIterator<Item = &'a str>>(dir: PathBuf, args: I) { fn validate<'a, I: IntoIterator<Item = &'a str>>(dir: PathBuf, args: I) {
let out = run_app(&dir.join("app.roc"), args); let out = run_app(&dir.join("app.roc"), args);
@ -70,11 +70,11 @@ mod glue_cli_run {
// Validate linux with the default linker. // Validate linux with the default linker.
if !(cfg!(target_os = "linux") && (skip_on_linux_surgical_linker.contains(&test_name_str))) { if !(cfg!(target_os = "linux") && (skip_on_linux_surgical_linker.contains(&test_name_str))) {
validate(dir.clone(), ["--build-host"]); validate(dir.clone(), ["--build-host", "--suppress-build-host-warning"]);
} }
if TEST_LEGACY_LINKER { if TEST_LEGACY_LINKER {
validate(dir, ["--build-host", "--linker=legacy"]); validate(dir, ["--build-host", "--suppress-build-host-warning", "--linker=legacy"]);
} }
} }
)* )*
@ -197,63 +197,56 @@ mod glue_cli_run {
assert_eq!(all_fixtures, &mut VecSet::default()); assert_eq!(all_fixtures, &mut VecSet::default());
} }
// fn generate_glue_for<'a, I: IntoIterator<Item = &'a str>>( fn generate_glue_for<'a, I: IntoIterator<Item = &'a str>>(
// platform_dir: &'a Path, platform_dir: &'a Path,
// args: I, args: I,
// ) -> Out { ) -> Out {
// let platform_module_path = platform_dir.join("platform.roc"); let platform_module_path = platform_dir.join("platform.roc");
// let glue_dir = platform_dir.join("test_glue"); let glue_dir = platform_dir.join("test_glue");
// let fixture_templates_dir = platform_dir let fixture_templates_dir = platform_dir
// .parent() .parent()
// .unwrap() .unwrap()
// .parent() .parent()
// .unwrap() .unwrap()
// .join("fixture-templates"); .join("fixture-templates");
// // Copy the rust template from the templates directory into the fixture dir. // Copy the rust template from the templates directory into the fixture dir.
// dircpy::CopyBuilder::new(fixture_templates_dir.join("rust"), platform_dir) dircpy::CopyBuilder::new(fixture_templates_dir.join("rust"), platform_dir)
// .overwrite(true) // overwrite any files that were already present .overwrite(true) // overwrite any files that were already present
// .run() .run()
// .unwrap(); .unwrap();
// // Delete the glue file to make sure we're actually regenerating it! // Delete the glue file to make sure we're actually regenerating it!
// if glue_dir.exists() { if glue_dir.exists() {
// fs::remove_dir_all(&glue_dir) std::fs::remove_dir_all(&glue_dir)
// .expect("Unable to remove test_glue dir in order to regenerate it in the test"); .expect("Unable to remove test_glue dir in order to regenerate it in the test");
// } }
// let rust_glue_spec = fixture_templates_dir let rust_glue_spec = fixture_templates_dir
// .parent() .parent()
// .unwrap() .unwrap()
// .parent() .parent()
// .unwrap() .unwrap()
// .join("src") .join("src")
// .join("RustGlue.roc"); .join("RustGlue.roc");
// // Generate a fresh test_glue for this platform // Generate a fresh test_glue for this platform
// let parts : Vec<_> = let parts : Vec<_> =
// // converting these all to String avoids lifetime issues // converting these all to String avoids lifetime issues
// std::iter::once("glue".to_string()).chain( std::iter::once("glue".to_string()).chain(
// args.into_iter().map(|arg| arg.to_string()).chain([ args.into_iter().map(|arg| arg.to_string()).chain([
// rust_glue_spec.to_str().unwrap().to_string(), rust_glue_spec.to_str().unwrap().to_string(),
// glue_dir.to_str().unwrap().to_string(), glue_dir.to_str().unwrap().to_string(),
// platform_module_path.to_str().unwrap().to_string(), platform_module_path.to_str().unwrap().to_string(),
// ]), ]),
// ).collect(); ).collect();
// let glue_out = run_glue(parts.iter());
// if has_error(&glue_out.stderr) { let glue_out = Run::new_roc().add_args(parts.iter()).run_glue();
// panic!(
// "`roc {}` command had unexpected stderr: {}",
// parts.join(" "),
// glue_out.stderr
// );
// }
// assert!(glue_out.status.success(), "bad status {glue_out:?}"); glue_out.assert_clean_success();
// glue_out glue_out
// } }
fn run_app<'a, 'b, I: IntoIterator<Item = &'a str>>(app_file: &'b Path, args: I) -> Out { fn run_app<'a, 'b, I: IntoIterator<Item = &'a str>>(app_file: &'b Path, args: I) -> Out {
// Generate test_glue for this platform // Generate test_glue for this platform