From 0b0ae7b28796674749827f5ebfc3429d1d475ca7 Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 8 Dec 2020 00:15:57 +0100 Subject: [PATCH] make it work! --- cli/src/build.rs | 7 +++- compiler/build/src/link.rs | 2 +- compiler/load/src/file.rs | 33 +++++++++++++++++++ examples/effect/Main.roc | 4 +-- examples/effect/thing/platform-dir/Cargo.toml | 2 +- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/cli/src/build.rs b/cli/src/build.rs index f0e4808d2e..4695598593 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -45,6 +45,9 @@ pub fn build_file( src_dir.as_path(), subs_by_module, )?; + + let path_to_platform = loaded.platform_path.clone(); + let app_o_file = roc_file_path.with_file_name("roc_app.o"); let buf = &mut String::with_capacity(1024); @@ -127,7 +130,9 @@ pub fn build_file( ); // Step 2: link the precompiled host and compiled app - let host_input_path = cwd.join("platform").join("host.o"); + let mut host_input_path = PathBuf::from(cwd); + host_input_path.push(&*path_to_platform); + host_input_path.push("host.o"); // TODO we should no longer need to do this once we have platforms on // a package repository, as we can then get precompiled hosts from there. diff --git a/compiler/build/src/link.rs b/compiler/build/src/link.rs index a5ce3379bd..d31eab0e83 100644 --- a/compiler/build/src/link.rs +++ b/compiler/build/src/link.rs @@ -88,7 +88,7 @@ pub fn rebuild_host(host_input_path: &Path) { .output() .unwrap(); - validate_output("host.rs", "cargo build --release", output); + validate_output("src/lib.rs", "cargo build --release", output); let output = Command::new("ld") .env_clear() diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index b7540d7647..9a31298694 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -559,6 +559,7 @@ struct ModuleHeader<'a> { imported_modules: MutSet, exposes: Vec, exposed_imports: MutMap, + to_platform: Option>, src: &'a [u8], module_timing: ModuleTiming, } @@ -600,6 +601,7 @@ pub struct MonomorphizedModule<'a> { pub interns: Interns, pub subs: Subs, pub output_path: Box, + pub platform_path: Box, pub can_problems: MutMap>, pub type_problems: MutMap>, pub mono_problems: MutMap>, @@ -692,6 +694,7 @@ struct State<'a> { pub stdlib: StdLib, pub exposed_types: SubsByModule, pub output_path: Option<&'a str>, + pub platform_path: Option>, pub opt_effect_module: Option, pub headers_parsed: MutSet, @@ -1272,6 +1275,7 @@ where goal_phase, stdlib, output_path: None, + platform_path: None, opt_effect_module: None, module_cache: ModuleCache::default(), dependencies: Dependencies::default(), @@ -1422,6 +1426,8 @@ fn update<'a>( } } + state.platform_path = state.platform_path.or(header.to_platform.clone()); + // store an ID to name mapping, so we know the file to read when fetching dependencies' headers for (name, id) in header.deps_by_name.iter() { state.module_cache.module_names.insert(*id, name.clone()); @@ -1811,6 +1817,7 @@ fn finish_specialization<'a>( procedures, module_cache, output_path, + platform_path, .. } = state; @@ -1827,11 +1834,33 @@ fn finish_specialization<'a>( .map(|(id, (path, src))| (id, (path, src.into()))) .collect(); + let path_to_platform = { + let package_or_path = match platform_path { + Some(To::ExistingPackage(shorthand)) => { + match (*state.arc_shorthands).lock().get(shorthand) { + Some(p_or_p) => p_or_p.clone(), + None => unreachable!(), + } + } + Some(To::NewPackage(p_or_p)) => p_or_p, + None => panic!("no platform!"), + }; + + match package_or_path { + PackageOrPath::Path(StrLiteral::PlainLine(path)) => path, + PackageOrPath::Path(_) => unreachable!("invalid"), + _ => todo!("packages"), + } + }; + + let platform_path = path_to_platform.into(); + MonomorphizedModule { can_problems, mono_problems, type_problems, output_path: output_path.unwrap_or(DEFAULT_APP_OUTPUT_PATH).into(), + platform_path, exposed_to_host, module_id: state.root_id, subs, @@ -2064,6 +2093,7 @@ fn parse_header<'a>( &[], header.exposes.into_bump_slice(), header.imports.into_bump_slice(), + None, parse_state, module_ids, ident_ids_by_module, @@ -2085,6 +2115,7 @@ fn parse_header<'a>( packages, header.provides.into_bump_slice(), header.imports.into_bump_slice(), + Some(header.to.value.clone()), parse_state, module_ids.clone(), ident_ids_by_module.clone(), @@ -2255,6 +2286,7 @@ fn send_header<'a>( packages: &'a [Located>], exposes: &'a [Located>], imports: &'a [Located>], + to_platform: Option>, parse_state: parser::State<'a>, module_ids: Arc>>, ident_ids_by_module: Arc>>, @@ -2421,6 +2453,7 @@ fn send_header<'a>( imported_modules, deps_by_name, exposes: exposed, + to_platform, src: parse_state.bytes, exposed_imports: scope, module_timing, diff --git a/examples/effect/Main.roc b/examples/effect/Main.roc index c0a51b8989..04d804618a 100644 --- a/examples/effect/Main.roc +++ b/examples/effect/Main.roc @@ -1,12 +1,12 @@ app "effect-example" - packages { base: "./thing/platform-dir" } + packages { base: "thing/platform-dir" } imports [ base.Task.{ Task, after } ] provides [ main ] to base # TODO `main : Task {}` does not work # it will then think that the `Task` module is unused # (if we also don't use any of the other importd symbols) -main : Task.Task {} +main : Task.Task {} as Fx main = when if 1 == 1 then True 3 else False 3.14 is True n -> Task.putLine (Str.fromInt n) diff --git a/examples/effect/thing/platform-dir/Cargo.toml b/examples/effect/thing/platform-dir/Cargo.toml index 70f3c1f86c..6e3f5e62aa 100644 --- a/examples/effect/thing/platform-dir/Cargo.toml +++ b/examples/effect/thing/platform-dir/Cargo.toml @@ -8,6 +8,6 @@ edition = "2018" crate-type = ["staticlib"] [dependencies] -roc_std = { path = "../../../roc_std" } +roc_std = { path = "../../../../roc_std" } [workspace]