make it work!

This commit is contained in:
Folkert 2020-12-08 00:15:57 +01:00
parent 7123269f30
commit 0b0ae7b287
5 changed files with 43 additions and 5 deletions

View File

@ -45,6 +45,9 @@ pub fn build_file(
src_dir.as_path(), src_dir.as_path(),
subs_by_module, 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 app_o_file = roc_file_path.with_file_name("roc_app.o");
let buf = &mut String::with_capacity(1024); let buf = &mut String::with_capacity(1024);
@ -127,7 +130,9 @@ pub fn build_file(
); );
// Step 2: link the precompiled host and compiled app // 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 // 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. // a package repository, as we can then get precompiled hosts from there.

View File

@ -88,7 +88,7 @@ pub fn rebuild_host(host_input_path: &Path) {
.output() .output()
.unwrap(); .unwrap();
validate_output("host.rs", "cargo build --release", output); validate_output("src/lib.rs", "cargo build --release", output);
let output = Command::new("ld") let output = Command::new("ld")
.env_clear() .env_clear()

View File

@ -559,6 +559,7 @@ struct ModuleHeader<'a> {
imported_modules: MutSet<ModuleId>, imported_modules: MutSet<ModuleId>,
exposes: Vec<Symbol>, exposes: Vec<Symbol>,
exposed_imports: MutMap<Ident, (Symbol, Region)>, exposed_imports: MutMap<Ident, (Symbol, Region)>,
to_platform: Option<To<'a>>,
src: &'a [u8], src: &'a [u8],
module_timing: ModuleTiming, module_timing: ModuleTiming,
} }
@ -600,6 +601,7 @@ pub struct MonomorphizedModule<'a> {
pub interns: Interns, pub interns: Interns,
pub subs: Subs, pub subs: Subs,
pub output_path: Box<str>, pub output_path: Box<str>,
pub platform_path: Box<str>,
pub can_problems: MutMap<ModuleId, Vec<roc_problem::can::Problem>>, pub can_problems: MutMap<ModuleId, Vec<roc_problem::can::Problem>>,
pub type_problems: MutMap<ModuleId, Vec<solve::TypeError>>, pub type_problems: MutMap<ModuleId, Vec<solve::TypeError>>,
pub mono_problems: MutMap<ModuleId, Vec<roc_mono::ir::MonoProblem>>, pub mono_problems: MutMap<ModuleId, Vec<roc_mono::ir::MonoProblem>>,
@ -692,6 +694,7 @@ struct State<'a> {
pub stdlib: StdLib, pub stdlib: StdLib,
pub exposed_types: SubsByModule, pub exposed_types: SubsByModule,
pub output_path: Option<&'a str>, pub output_path: Option<&'a str>,
pub platform_path: Option<To<'a>>,
pub opt_effect_module: Option<ModuleId>, pub opt_effect_module: Option<ModuleId>,
pub headers_parsed: MutSet<ModuleId>, pub headers_parsed: MutSet<ModuleId>,
@ -1272,6 +1275,7 @@ where
goal_phase, goal_phase,
stdlib, stdlib,
output_path: None, output_path: None,
platform_path: None,
opt_effect_module: None, opt_effect_module: None,
module_cache: ModuleCache::default(), module_cache: ModuleCache::default(),
dependencies: Dependencies::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 // 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() { for (name, id) in header.deps_by_name.iter() {
state.module_cache.module_names.insert(*id, name.clone()); state.module_cache.module_names.insert(*id, name.clone());
@ -1811,6 +1817,7 @@ fn finish_specialization<'a>(
procedures, procedures,
module_cache, module_cache,
output_path, output_path,
platform_path,
.. ..
} = state; } = state;
@ -1827,11 +1834,33 @@ fn finish_specialization<'a>(
.map(|(id, (path, src))| (id, (path, src.into()))) .map(|(id, (path, src))| (id, (path, src.into())))
.collect(); .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 { MonomorphizedModule {
can_problems, can_problems,
mono_problems, mono_problems,
type_problems, type_problems,
output_path: output_path.unwrap_or(DEFAULT_APP_OUTPUT_PATH).into(), output_path: output_path.unwrap_or(DEFAULT_APP_OUTPUT_PATH).into(),
platform_path,
exposed_to_host, exposed_to_host,
module_id: state.root_id, module_id: state.root_id,
subs, subs,
@ -2064,6 +2093,7 @@ fn parse_header<'a>(
&[], &[],
header.exposes.into_bump_slice(), header.exposes.into_bump_slice(),
header.imports.into_bump_slice(), header.imports.into_bump_slice(),
None,
parse_state, parse_state,
module_ids, module_ids,
ident_ids_by_module, ident_ids_by_module,
@ -2085,6 +2115,7 @@ fn parse_header<'a>(
packages, packages,
header.provides.into_bump_slice(), header.provides.into_bump_slice(),
header.imports.into_bump_slice(), header.imports.into_bump_slice(),
Some(header.to.value.clone()),
parse_state, parse_state,
module_ids.clone(), module_ids.clone(),
ident_ids_by_module.clone(), ident_ids_by_module.clone(),
@ -2255,6 +2286,7 @@ fn send_header<'a>(
packages: &'a [Located<PackageEntry<'a>>], packages: &'a [Located<PackageEntry<'a>>],
exposes: &'a [Located<ExposesEntry<'a, &'a str>>], exposes: &'a [Located<ExposesEntry<'a, &'a str>>],
imports: &'a [Located<ImportsEntry<'a>>], imports: &'a [Located<ImportsEntry<'a>>],
to_platform: Option<To<'a>>,
parse_state: parser::State<'a>, parse_state: parser::State<'a>,
module_ids: Arc<Mutex<PackageModuleIds<'a>>>, module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>, ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
@ -2421,6 +2453,7 @@ fn send_header<'a>(
imported_modules, imported_modules,
deps_by_name, deps_by_name,
exposes: exposed, exposes: exposed,
to_platform,
src: parse_state.bytes, src: parse_state.bytes,
exposed_imports: scope, exposed_imports: scope,
module_timing, module_timing,

View File

@ -1,12 +1,12 @@
app "effect-example" app "effect-example"
packages { base: "./thing/platform-dir" } packages { base: "thing/platform-dir" }
imports [ base.Task.{ Task, after } ] imports [ base.Task.{ Task, after } ]
provides [ main ] to base provides [ main ] to base
# TODO `main : Task {}` does not work # TODO `main : Task {}` does not work
# it will then think that the `Task` module is unused # it will then think that the `Task` module is unused
# (if we also don't use any of the other importd symbols) # (if we also don't use any of the other importd symbols)
main : Task.Task {} main : Task.Task {} as Fx
main = main =
when if 1 == 1 then True 3 else False 3.14 is when if 1 == 1 then True 3 else False 3.14 is
True n -> Task.putLine (Str.fromInt n) True n -> Task.putLine (Str.fromInt n)

View File

@ -8,6 +8,6 @@ edition = "2018"
crate-type = ["staticlib"] crate-type = ["staticlib"]
[dependencies] [dependencies]
roc_std = { path = "../../../roc_std" } roc_std = { path = "../../../../roc_std" }
[workspace] [workspace]