mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
make Pkg-Config into a module
This commit is contained in:
parent
4c16e1772d
commit
5b521dccf4
2 changed files with 70 additions and 14 deletions
|
@ -1933,10 +1933,14 @@ fn load_pkg_config<'a>(
|
||||||
let parse_header_duration = parse_start.elapsed().unwrap();
|
let parse_header_duration = parse_start.elapsed().unwrap();
|
||||||
|
|
||||||
// Insert the first entries for this module's timings
|
// Insert the first entries for this module's timings
|
||||||
let mut module_timing = ModuleTiming::new(module_start_time);
|
let mut pkg_module_timing = ModuleTiming::new(module_start_time);
|
||||||
|
let mut effect_module_timing = ModuleTiming::new(module_start_time);
|
||||||
|
|
||||||
module_timing.read_roc_file = file_io_duration;
|
pkg_module_timing.read_roc_file = file_io_duration;
|
||||||
module_timing.parse_header = parse_header_duration;
|
pkg_module_timing.parse_header = parse_header_duration;
|
||||||
|
|
||||||
|
effect_module_timing.read_roc_file = file_io_duration;
|
||||||
|
effect_module_timing.parse_header = parse_header_duration;
|
||||||
|
|
||||||
match parsed {
|
match parsed {
|
||||||
Ok((ast::Module::Interface { header }, _parse_state)) => {
|
Ok((ast::Module::Interface { header }, _parse_state)) => {
|
||||||
|
@ -1951,16 +1955,34 @@ fn load_pkg_config<'a>(
|
||||||
header
|
header
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
Ok((ast::Module::Platform { header }, _parse_state)) => fabricate_effects_module(
|
Ok((ast::Module::Platform { header }, parser_state)) => {
|
||||||
|
// make a Pkg-Config module that ultimately exposes `main` to the host
|
||||||
|
let pkg_config_module_msg = fabricate_pkg_config_module(
|
||||||
|
arena,
|
||||||
|
shorthand,
|
||||||
|
filename,
|
||||||
|
parser_state,
|
||||||
|
module_ids.clone(),
|
||||||
|
ident_ids_by_module.clone(),
|
||||||
|
mode,
|
||||||
|
&header,
|
||||||
|
pkg_module_timing,
|
||||||
|
)
|
||||||
|
.map(|x| x.1)?;
|
||||||
|
|
||||||
|
let effects_module_msg = fabricate_effects_module(
|
||||||
arena,
|
arena,
|
||||||
shorthand,
|
shorthand,
|
||||||
module_ids,
|
module_ids,
|
||||||
ident_ids_by_module,
|
ident_ids_by_module,
|
||||||
mode,
|
mode,
|
||||||
header,
|
header,
|
||||||
module_timing,
|
effect_module_timing,
|
||||||
)
|
)
|
||||||
.map(|x| x.1),
|
.map(|x| x.1)?;
|
||||||
|
|
||||||
|
Ok(Msg::Many(vec![effects_module_msg, pkg_config_module_msg]))
|
||||||
|
}
|
||||||
Err((fail, _)) => Err(LoadingProblem::ParsingFailed { filename, fail }),
|
Err((fail, _)) => Err(LoadingProblem::ParsingFailed { filename, fail }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2572,6 +2594,40 @@ fn run_solve<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
fn fabricate_pkg_config_module<'a>(
|
||||||
|
arena: &'a Bump,
|
||||||
|
shorthand: &'a str,
|
||||||
|
filename: PathBuf,
|
||||||
|
parse_state: parser::State<'a>,
|
||||||
|
module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
|
||||||
|
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
||||||
|
mode: Mode,
|
||||||
|
header: &PlatformHeader<'a>,
|
||||||
|
module_timing: ModuleTiming,
|
||||||
|
) -> Result<(ModuleId, Msg<'a>), LoadingProblem> {
|
||||||
|
let name = format!("{}.Pkg-Config", shorthand);
|
||||||
|
Ok(send_header(
|
||||||
|
Located {
|
||||||
|
region: header.name.region,
|
||||||
|
value: AppOrInterfaceName::Interface(roc_parse::header::ModuleName::new(
|
||||||
|
arena.alloc(name),
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
filename,
|
||||||
|
Some(shorthand),
|
||||||
|
&[],
|
||||||
|
// header.exposes.into_bump_slice(),
|
||||||
|
&[],
|
||||||
|
header.imports.clone().into_bump_slice(),
|
||||||
|
None,
|
||||||
|
parse_state,
|
||||||
|
module_ids,
|
||||||
|
ident_ids_by_module,
|
||||||
|
module_timing,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn fabricate_effects_module<'a>(
|
fn fabricate_effects_module<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
|
|
|
@ -2,7 +2,7 @@ platform folkertdev/foo
|
||||||
requires { main : Effect {} }
|
requires { main : Effect {} }
|
||||||
exposes []
|
exposes []
|
||||||
packages {}
|
packages {}
|
||||||
imports [ File ]
|
imports [ ]
|
||||||
provides [ mainForHost ]
|
provides [ mainForHost ]
|
||||||
effects Effect
|
effects Effect
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue