Skip to content

Commit

Permalink
internal: tweak native flags for new toolchain layout (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash authored Dec 31, 2024
1 parent cb463b9 commit 2b6d37f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 54 deletions.
51 changes: 34 additions & 17 deletions crates/moon/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,49 @@ fn run_single_mbt_file(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Resu
if cmd.build_flags.enable_value_tracing {
build_package_command.push("-enable-value-tracing".to_string());
}
let link_core_command = [
"link-core",
&moonutil::moon_dir::core_core(target_backend)
let mut link_core_command = vec![
"link-core".to_string(),
moonutil::moon_dir::core_core(target_backend)
.display()
.to_string(),
&(output_artifact_path
output_artifact_path
.join(format!("{}.core", file_name))
.display()
.to_string()),
"-o",
&output_wasm_or_js_path.display().to_string(),
"-pkg-sources",
&format!("{}:{}", pkg_name, mbt_file_parent_path.display()),
"-pkg-sources",
&format!(
.to_string(),
"-o".to_string(),
output_wasm_or_js_path.display().to_string(),
"-pkg-sources".to_string(),
format!("{}:{}", pkg_name, mbt_file_parent_path.display()),
"-pkg-sources".to_string(),
format!(
"{}:{}",
MOONBITLANG_CORE,
moonutil::moon_dir::core().display()
),
"-g",
"-O0",
"-source-map",
"-target",
target_backend.to_flag(),
"-g".to_string(),
"-O0".to_string(),
"-source-map".to_string(),
"-target".to_string(),
target_backend.to_flag().to_string(),
];

if target_backend == TargetBackend::Native {
let moonc_path = which::which("moonc").context("moonc not found in PATH")?;
let moon_home = moonc_path.parent().unwrap().parent().unwrap();
let moon_include_path = moon_home.join("include");
let moon_lib_path = moon_home.join("lib");
let tcc_path = moon_home.join("bin").join("internal").join("tcc");

link_core_command.push("-cc".to_string());
link_core_command.push(tcc_path.display().to_string());
link_core_command.push("-cc-flags".to_string());
link_core_command.push(format!(
"-L{} -I{} -DMOONBIT_NATIVE_NO_SYS_HEADER",
moon_lib_path.display(),
moon_include_path.display()
));
}

if cli.dry_run {
println!("moonc {}", build_package_command.join(" "));
println!("moonc {}", link_core_command.join(" "));
Expand All @@ -181,7 +198,7 @@ fn run_single_mbt_file(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Resu
}

let moonc_link_core = std::process::Command::new("moonc")
.args(link_core_command)
.args(&link_core_command)
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.spawn()?
Expand Down
2 changes: 1 addition & 1 deletion crates/moon/tests/test_cases/cond_comp.in/moon.test
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
$ moon build --dry-run --target native --sort-input --nostd --debug
moonc build-package ./src/lib/all.mbt ./src/lib/native_and_wasm.mbt ./src/lib/native_only.mbt ./src/lib/not_js.mbt ./src/lib/only_debug.mbt -o ./target/native/debug/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target native -g -O0
moonc build-package ./src/main/main.mbt -o ./target/native/debug/build/main/main.core -pkg username/hello/main -is-main -i ./target/native/debug/build/lib/lib.mi:lib -pkg-sources username/hello/main:./src/main -target native -g -O0
moonc link-core ./target/native/debug/build/lib/lib.core ./target/native/debug/build/main/main.core -main username/hello/main -o ./target/native/debug/build/main/main.exe -pkg-config-path ./src/main/moon.pkg.json -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/main:./src/main -target native -g -O0 -cc tcc -cc-flags "-L$MOON_HOME/bin -I$MOON_HOME/bin -DMOONBIT_NATIVE_NO_SYS_HEADER"
moonc link-core ./target/native/debug/build/lib/lib.core ./target/native/debug/build/main/main.core -main username/hello/main -o ./target/native/debug/build/main/main.exe -pkg-config-path ./src/main/moon.pkg.json -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/main:./src/main -target native -g -O0 -cc $MOON_HOME/bin/internal/tcc -cc-flags "-L$MOON_HOME/lib -I$MOON_HOME/include -DMOONBIT_NATIVE_NO_SYS_HEADER"

$ moon check --sort-input

Expand Down
Loading

0 comments on commit 2b6d37f

Please sign in to comment.