diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 5cc55f1b52..cb4f22edfe 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -143,30 +143,6 @@ mod cli_run { ); } - #[test] - #[serial(multi_module)] - fn run_multi_module() { - check_output( - &example_file("multi-module", "Quicksort.roc"), - "quicksort", - &[], - "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n", - false, - ); - } - - #[test] - #[serial(multi_module)] - fn run_multi_module_optimized() { - check_output( - &example_file("multi-module", "Quicksort.roc"), - "quicksort", - &["--optimize"], - "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n", - false, - ); - } - #[test] #[serial(multi_module)] // TODO: Stop ignoring this test once we are correctly freeing the RocList even when in dev build. diff --git a/cli/tests/fixtures/multi-dep-str/Main.roc b/cli/tests/fixtures/multi-dep-str/Main.roc index 69af7c5d9b..60d452bcc8 100644 --- a/cli/tests/fixtures/multi-dep-str/Main.roc +++ b/cli/tests/fixtures/multi-dep-str/Main.roc @@ -1,4 +1,7 @@ -app "multi-dep-str" imports [ Dep1 ] provides [ main ] to "./platform" +app "multi-dep-str" + packages { base: "platform" } + imports [ Dep1 ] + provides [ main ] to base main : Str main = Dep1.str1 diff --git a/cli/tests/fixtures/multi-dep-str/platform/Pkg-Config.roc b/cli/tests/fixtures/multi-dep-str/platform/Pkg-Config.roc index 6e7af88a5c..1ff6c7b8b8 100644 --- a/cli/tests/fixtures/multi-dep-str/platform/Pkg-Config.roc +++ b/cli/tests/fixtures/multi-dep-str/platform/Pkg-Config.roc @@ -3,5 +3,8 @@ platform examples/multi-module exposes [] packages {} imports [] - provides [ main ] + provides [ mainForHost ] effects Effect {} + +mainForHost : Str +mainForHost = main diff --git a/cli/tests/fixtures/multi-dep-str/platform/src/lib.rs b/cli/tests/fixtures/multi-dep-str/platform/src/lib.rs index 4d390b0560..c6a68ca745 100644 --- a/cli/tests/fixtures/multi-dep-str/platform/src/lib.rs +++ b/cli/tests/fixtures/multi-dep-str/platform/src/lib.rs @@ -3,7 +3,7 @@ use roc_std::RocStr; use std::str; extern "C" { - #[link_name = "roc__main_1_exposed"] + #[link_name = "roc__mainForHost_1_exposed"] fn say_hello(output: &mut RocCallResult) -> (); } diff --git a/cli/tests/fixtures/multi-dep-thunk/Main.roc b/cli/tests/fixtures/multi-dep-thunk/Main.roc index 2b2e3fc233..ae6243978b 100644 --- a/cli/tests/fixtures/multi-dep-thunk/Main.roc +++ b/cli/tests/fixtures/multi-dep-thunk/Main.roc @@ -1,4 +1,7 @@ -app "multi-dep-thunk" imports [ Dep1 ] provides [ main ] to "./platform" +app "multi-dep-thunk" + packages { base: "platform" } + imports [ Dep1 ] + provides [ main ] to base main : Str main = Dep1.value1 {} diff --git a/cli/tests/fixtures/multi-dep-thunk/platform/Pkg-Config.roc b/cli/tests/fixtures/multi-dep-thunk/platform/Pkg-Config.roc index 86d0701468..a080298820 100644 --- a/cli/tests/fixtures/multi-dep-thunk/platform/Pkg-Config.roc +++ b/cli/tests/fixtures/multi-dep-thunk/platform/Pkg-Config.roc @@ -3,5 +3,8 @@ platform examples/multi-dep-thunk exposes [] packages {} imports [] - provides [ main ] + provides [ mainForHost ] effects Effect {} + +mainForHost : Str +mainForHost = main diff --git a/cli/tests/fixtures/multi-dep-thunk/platform/src/lib.rs b/cli/tests/fixtures/multi-dep-thunk/platform/src/lib.rs index 4d390b0560..c6a68ca745 100644 --- a/cli/tests/fixtures/multi-dep-thunk/platform/src/lib.rs +++ b/cli/tests/fixtures/multi-dep-thunk/platform/src/lib.rs @@ -3,7 +3,7 @@ use roc_std::RocStr; use std::str; extern "C" { - #[link_name = "roc__main_1_exposed"] + #[link_name = "roc__mainForHost_1_exposed"] fn say_hello(output: &mut RocCallResult) -> (); } diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 0d39c807a3..7a0d80ca0e 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -1618,7 +1618,14 @@ fn update<'a>( let work = state.dependencies.notify(module_id, Phase::SolveTypes); - if Some(module_id) == state.platform_id { + // if there is a platform, the Pkg-Config module provides host-exposed, + // otherwise the App module exposes host-exposed + let is_host_exposed = match state.platform_id { + None => module_id == state.root_id, + Some(platform_id) => module_id == platform_id, + }; + + if is_host_exposed { state .exposed_to_host .extend(solved_module.exposed_vars_by_symbol.iter().copied()); @@ -2505,6 +2512,7 @@ fn send_header<'a>( ) } +// TODO refactor so more logic is shared with `send_header` #[allow(clippy::too_many_arguments)] fn send_header_two<'a>( arena: &'a Bump, diff --git a/examples/quicksort/Quicksort.roc b/examples/quicksort/Quicksort.roc index 0092b7b527..59bb6d47f0 100644 --- a/examples/quicksort/Quicksort.roc +++ b/examples/quicksort/Quicksort.roc @@ -1,4 +1,7 @@ -app "quicksort" provides [ quicksort ] to "./platform" +app "quicksort" + packages { base: "platform" } + imports [] + provides [ quicksort ] to base quicksort = \originalList -> diff --git a/examples/quicksort/platform/Pkg-Config.roc b/examples/quicksort/platform/Pkg-Config.roc index c26ae3837c..7e59c04a27 100644 --- a/examples/quicksort/platform/Pkg-Config.roc +++ b/examples/quicksort/platform/Pkg-Config.roc @@ -1,7 +1,10 @@ platform examples/quicksort - requires { quicksort : List (Num a) -> List (Num a) } + requires { quicksort : List I64 -> List I64 } exposes [] packages {} imports [] - provides [ main ] + provides [ mainForHost ] effects Effect {} + +mainForHost : List I64 -> List I64 +mainForHost = \list -> quicksort list diff --git a/examples/quicksort/platform/src/lib.rs b/examples/quicksort/platform/src/lib.rs index 53cf2f83b9..0a626cbae4 100644 --- a/examples/quicksort/platform/src/lib.rs +++ b/examples/quicksort/platform/src/lib.rs @@ -3,7 +3,7 @@ use roc_std::RocList; use std::time::SystemTime; extern "C" { - #[link_name = "roc__quicksort_1_exposed"] + #[link_name = "roc__mainForHost_1_exposed"] fn quicksort(list: RocList, output: &mut RocCallResult>) -> (); } diff --git a/examples/shared-quicksort/platform/Pkg-Config.roc b/examples/shared-quicksort/platform/Pkg-Config.roc index 18e1f25552..061e86aaa6 100644 --- a/examples/shared-quicksort/platform/Pkg-Config.roc +++ b/examples/shared-quicksort/platform/Pkg-Config.roc @@ -1,12 +1,16 @@ platform examples/shared-quicksort - requires { main : Effect {} } + requires { quicksort : List I64 -> List I64 } exposes [] packages {} imports [] provides [ mainForHost ] effects Effect { - putChar : Int -> Effect {}, + putChar : I64 -> Effect {}, putLine : Str -> Effect {}, getLine : Effect Str } + +mainForHost : List I64 -> List I64 +mainForHost = \list -> quicksort list + diff --git a/examples/shared-quicksort/platform/src/lib.rs b/examples/shared-quicksort/platform/src/lib.rs index 974dc2592c..acfbb9e263 100644 --- a/examples/shared-quicksort/platform/src/lib.rs +++ b/examples/shared-quicksort/platform/src/lib.rs @@ -5,7 +5,7 @@ use roc_std::RocList; use std::time::SystemTime; extern "C" { - #[link_name = "roc__quicksort_1_exposed"] + #[link_name = "roc__mainForHost_1_exposed"] fn quicksort(list: RocList, output: &mut RocCallResult>) -> (); }