From dd93e215fe032f8bad563b299421e9cd068473a6 Mon Sep 17 00:00:00 2001 From: Young-Flash Date: Wed, 22 Jan 2025 16:58:24 +0800 Subject: [PATCH] Revert "internal: use cc / cl by default instead of tcc" This reverts commit ef6572f6da68f9c1c629f0cc8165e6d505791a66. --- .../tests/test_cases/cond_comp.in/moon.test | 5 ++++ crates/moon/tests/test_cases/mod.rs | 28 ++++++------------- crates/moonutil/src/common.rs | 24 +++++++++++++--- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/crates/moon/tests/test_cases/cond_comp.in/moon.test b/crates/moon/tests/test_cases/cond_comp.in/moon.test index 7476121a..132224b6 100644 --- a/crates/moon/tests/test_cases/cond_comp.in/moon.test +++ b/crates/moon/tests/test_cases/cond_comp.in/moon.test @@ -52,6 +52,11 @@ moonc build-package ./src/main/main.mbt -o ./target/js/release/bundle/main/main.core -pkg username/hello/main -is-main -i ./target/js/release/bundle/lib/lib.mi:lib -pkg-sources username/hello/main:./src/main -target js moonc bundle-core ./target/js/release/bundle/lib/lib.core ./target/js/release/bundle/main/main.core -o ./target/js/release/bundle/hello.core + $ 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 $MOON_HOME/bin/internal/tcc -cc-flags "-L$MOON_HOME/lib -I$MOON_HOME/include -DMOONBIT_NATIVE_NO_SYS_HEADER" + $ moon check --sort-input Warning: [1002] diff --git a/crates/moon/tests/test_cases/mod.rs b/crates/moon/tests/test_cases/mod.rs index c882fe7c..ab5d2ce5 100644 --- a/crates/moon/tests/test_cases/mod.rs +++ b/crates/moon/tests/test_cases/mod.rs @@ -7455,7 +7455,7 @@ fn test_use_cc_for_native_release() { expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/native/release/build/lib/lib.core -pkg moonbitlang/hello/lib -std-path $MOON_HOME/lib/core/target/native/release/bundle -pkg-sources moonbitlang/hello/lib:./lib -target native moonc build-package ./main/main.mbt -o ./target/native/release/build/main/main.core -pkg moonbitlang/hello/main -is-main -std-path $MOON_HOME/lib/core/target/native/release/bundle -i ./target/native/release/build/lib/lib.mi:lib -pkg-sources moonbitlang/hello/main:./main -target native - moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/release/build/lib/lib.core ./target/native/release/build/main/main.core -main moonbitlang/hello/main -o ./target/native/release/build/main/main.exe -pkg-config-path ./main/moon.pkg.json -pkg-sources moonbitlang/hello/lib:./lib -pkg-sources moonbitlang/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target native -cc cc -cc-flags "-I$MOON_HOME/include -O2 $MOON_HOME/lib/libmoonbitrun.o -fwrapv -fno-strict-aliasing" -cc-link-flags -lm + moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/release/build/lib/lib.core ./target/native/release/build/main/main.core -main moonbitlang/hello/main -o ./target/native/release/build/main/main.exe -pkg-config-path ./main/moon.pkg.json -pkg-sources moonbitlang/hello/lib:./lib -pkg-sources moonbitlang/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target native -cc $MOON_HOME/bin/internal/tcc -cc-flags "-L$MOON_HOME/lib -I$MOON_HOME/include -DMOONBIT_NATIVE_NO_SYS_HEADER" "#]], ); check( @@ -7473,7 +7473,7 @@ fn test_use_cc_for_native_release() { expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/native/debug/build/lib/lib.core -pkg moonbitlang/hello/lib -std-path $MOON_HOME/lib/core/target/native/release/bundle -pkg-sources moonbitlang/hello/lib:./lib -target native -g -O0 moonc build-package ./main/main.mbt -o ./target/native/debug/build/main/main.core -pkg moonbitlang/hello/main -is-main -std-path $MOON_HOME/lib/core/target/native/release/bundle -i ./target/native/debug/build/lib/lib.mi:lib -pkg-sources moonbitlang/hello/main:./main -target native -g -O0 - moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/debug/build/lib/lib.core ./target/native/debug/build/main/main.core -main moonbitlang/hello/main -o ./target/native/debug/build/main/main.exe -pkg-config-path ./main/moon.pkg.json -pkg-sources moonbitlang/hello/lib:./lib -pkg-sources moonbitlang/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target native -g -O0 -cc cc -cc-flags "-I$MOON_HOME/include -O2 $MOON_HOME/lib/libmoonbitrun.o -fwrapv -fno-strict-aliasing" -cc-link-flags -lm + moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/debug/build/lib/lib.core ./target/native/debug/build/main/main.core -main moonbitlang/hello/main -o ./target/native/debug/build/main/main.exe -pkg-config-path ./main/moon.pkg.json -pkg-sources moonbitlang/hello/lib:./lib -pkg-sources moonbitlang/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -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" "#]], ); } @@ -7516,7 +7516,7 @@ fn test_use_cc_for_native_release() { expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/native/release/build/lib/lib.core -pkg moonbitlang/hello/lib -std-path $MOON_HOME/lib/core/target/native/release/bundle -pkg-sources moonbitlang/hello/lib:./lib -target native moonc build-package ./main/main.mbt -o ./target/native/release/build/main/main.core -pkg moonbitlang/hello/main -is-main -std-path $MOON_HOME/lib/core/target/native/release/bundle -i ./target/native/release/build/lib/lib.mi:lib -pkg-sources moonbitlang/hello/main:./main -target native - moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/release/build/lib/lib.core ./target/native/release/build/main/main.core -main moonbitlang/hello/main -o ./target/native/release/build/main/main.exe -pkg-config-path ./main/moon.pkg.json -pkg-sources moonbitlang/hello/lib:./lib -pkg-sources moonbitlang/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target native -cc cc -cc-flags "-I$MOON_HOME/include -O2 $MOON_HOME/lib/libmoonbitrun.o -fwrapv -fno-strict-aliasing" -cc-link-flags -lm + moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/release/build/lib/lib.core ./target/native/release/build/main/main.core -main moonbitlang/hello/main -o ./target/native/release/build/main/main.exe -pkg-config-path ./main/moon.pkg.json -pkg-sources moonbitlang/hello/lib:./lib -pkg-sources moonbitlang/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target native -cc $MOON_HOME/bin/internal/tcc -cc-flags "-L$MOON_HOME/lib -I$MOON_HOME/include -DMOONBIT_NATIVE_NO_SYS_HEADER" ./target/native/release/build/main/main.exe "#]], ); @@ -7536,7 +7536,7 @@ fn test_use_cc_for_native_release() { expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/native/debug/build/lib/lib.core -pkg moonbitlang/hello/lib -std-path $MOON_HOME/lib/core/target/native/release/bundle -pkg-sources moonbitlang/hello/lib:./lib -target native -g -O0 moonc build-package ./main/main.mbt -o ./target/native/debug/build/main/main.core -pkg moonbitlang/hello/main -is-main -std-path $MOON_HOME/lib/core/target/native/release/bundle -i ./target/native/debug/build/lib/lib.mi:lib -pkg-sources moonbitlang/hello/main:./main -target native -g -O0 - moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/debug/build/lib/lib.core ./target/native/debug/build/main/main.core -main moonbitlang/hello/main -o ./target/native/debug/build/main/main.exe -pkg-config-path ./main/moon.pkg.json -pkg-sources moonbitlang/hello/lib:./lib -pkg-sources moonbitlang/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target native -g -O0 -cc cc -cc-flags "-I$MOON_HOME/include -O2 $MOON_HOME/lib/libmoonbitrun.o -fwrapv -fno-strict-aliasing" -cc-link-flags -lm + moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/debug/build/lib/lib.core ./target/native/debug/build/main/main.core -main moonbitlang/hello/main -o ./target/native/debug/build/main/main.exe -pkg-config-path ./main/moon.pkg.json -pkg-sources moonbitlang/hello/lib:./lib -pkg-sources moonbitlang/hello/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -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" ./target/native/debug/build/main/main.exe "#]], ); @@ -7580,10 +7580,10 @@ fn test_use_cc_for_native_release() { expect![[r#" moon generate-test-driver --source-dir . --target-dir ./target --package moonbitlang/hello/lib --sort-input --target native --driver-kind whitebox moonc build-package ./lib/hello.mbt ./lib/hello_wbtest.mbt ./target/native/debug/test/lib/__generated_driver_for_whitebox_test.mbt -o ./target/native/debug/test/lib/lib.whitebox_test.core -pkg moonbitlang/hello/lib -is-main -std-path $MOON_HOME/lib/core/target/native/release/bundle -pkg-sources moonbitlang/hello/lib:./lib -target native -g -O0 -whitebox-test -no-mi - moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/debug/test/lib/lib.whitebox_test.core -main moonbitlang/hello/lib -o ./target/native/debug/test/lib/lib.whitebox_test.exe -test-mode -pkg-config-path ./lib/moon.pkg.json -pkg-sources moonbitlang/hello/lib:./lib -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target native -g -O0 -cc cc -cc-flags "-I$MOON_HOME/include -O2 $MOON_HOME/lib/libmoonbitrun.o -fwrapv -fno-strict-aliasing" -cc-link-flags -lm + moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/debug/test/lib/lib.whitebox_test.core -main moonbitlang/hello/lib -o ./target/native/debug/test/lib/lib.whitebox_test.exe -test-mode -pkg-config-path ./lib/moon.pkg.json -pkg-sources moonbitlang/hello/lib:./lib -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -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 generate-test-driver --source-dir . --target-dir ./target --package moonbitlang/hello/lib --sort-input --target native --driver-kind internal moonc build-package ./lib/hello.mbt ./target/native/debug/test/lib/__generated_driver_for_internal_test.mbt -o ./target/native/debug/test/lib/lib.internal_test.core -pkg moonbitlang/hello/lib -is-main -std-path $MOON_HOME/lib/core/target/native/release/bundle -pkg-sources moonbitlang/hello/lib:./lib -target native -g -O0 -no-mi - moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/debug/test/lib/lib.internal_test.core -main moonbitlang/hello/lib -o ./target/native/debug/test/lib/lib.internal_test.exe -test-mode -pkg-config-path ./lib/moon.pkg.json -pkg-sources moonbitlang/hello/lib:./lib -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -target native -g -O0 -cc cc -cc-flags "-I$MOON_HOME/include -O2 $MOON_HOME/lib/libmoonbitrun.o -fwrapv -fno-strict-aliasing" -cc-link-flags -lm + moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/debug/test/lib/lib.internal_test.core -main moonbitlang/hello/lib -o ./target/native/debug/test/lib/lib.internal_test.exe -test-mode -pkg-config-path ./lib/moon.pkg.json -pkg-sources moonbitlang/hello/lib:./lib -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -exported_functions moonbit_test_driver_internal_execute,moonbit_test_driver_finish -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" "#]], ); } @@ -7614,7 +7614,6 @@ fn test_moon_package_list() { } #[test] -#[cfg(unix)] fn test_native_backend_cc_flags() { let dir = TestDir::new("native_backend_cc_flags.in"); check( @@ -7625,7 +7624,7 @@ fn test_native_backend_cc_flags() { expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/native/release/build/lib/lib.core -pkg moon_new/lib -std-path $MOON_HOME/lib/core/target/native/release/bundle -pkg-sources moon_new/lib:./lib -target native moonc build-package ./main/main.mbt -o ./target/native/release/build/main/main.core -pkg moon_new/main -is-main -std-path $MOON_HOME/lib/core/target/native/release/bundle -i ./target/native/release/build/lib/lib.mi:lib -pkg-sources moon_new/main:./main -target native - moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/release/build/lib/lib.core ./target/native/release/build/main/main.core -main moon_new/main -o ./target/native/release/build/main/main.exe -pkg-config-path ./main/moon.pkg.json -pkg-sources moon_new/lib:./lib -pkg-sources moon_new/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target native -cc cc -cc-flags "-I$MOON_HOME/include -O2 $MOON_HOME/lib/libmoonbitrun.o -fwrapv -fno-strict-aliasing" -cc-link-flags -lm + moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/release/build/lib/lib.core ./target/native/release/build/main/main.core -main moon_new/main -o ./target/native/release/build/main/main.exe -pkg-config-path ./main/moon.pkg.json -pkg-sources moon_new/lib:./lib -pkg-sources moon_new/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target native -cc $MOON_HOME/bin/internal/tcc -cc-flags "-L$MOON_HOME/lib -I$MOON_HOME/include -DMOONBIT_NATIVE_NO_SYS_HEADER" moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/release/build/lib/lib.core -main moon_new/lib -o ./target/native/release/build/lib/lib.exe -pkg-config-path ./lib/moon.pkg.json -pkg-sources moon_new/lib:./lib -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target native -cc cc -cc-flags "-I$MOON_HOME/include -fno-strict-aliasing ccflags fasd" -cc-link-flags cclinkflags "#]], ); @@ -7679,7 +7678,7 @@ fn test_native_backend_cc_flags() { expect![[r#" moonc build-package ./lib/hello.mbt -o ./target/native/release/build/lib/lib.core -pkg moon_new/lib -std-path $MOON_HOME/lib/core/target/native/release/bundle -pkg-sources moon_new/lib:./lib -target native moonc build-package ./main/main.mbt -o ./target/native/release/build/main/main.core -pkg moon_new/main -is-main -std-path $MOON_HOME/lib/core/target/native/release/bundle -i ./target/native/release/build/lib/lib.mi:lib -pkg-sources moon_new/main:./main -target native - moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/release/build/lib/lib.core ./target/native/release/build/main/main.core -main moon_new/main -o ./target/native/release/build/main/main.exe -pkg-config-path ./main/moon.pkg.json -pkg-sources moon_new/lib:./lib -pkg-sources moon_new/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target native -cc cc -cc-flags "-I$MOON_HOME/include -O2 $MOON_HOME/lib/libmoonbitrun.o -fwrapv -fno-strict-aliasing" -cc-link-flags -lm + moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/release/build/lib/lib.core ./target/native/release/build/main/main.core -main moon_new/main -o ./target/native/release/build/main/main.exe -pkg-config-path ./main/moon.pkg.json -pkg-sources moon_new/lib:./lib -pkg-sources moon_new/main:./main -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target native -cc $MOON_HOME/bin/internal/tcc -cc-flags "-L$MOON_HOME/lib -I$MOON_HOME/include -DMOONBIT_NATIVE_NO_SYS_HEADER" moonc link-core $MOON_HOME/lib/core/target/native/release/bundle/core.core ./target/native/release/build/lib/lib.core -main moon_new/lib -o ./target/native/release/build/lib/lib.exe -pkg-config-path ./lib/moon.pkg.json -pkg-sources moon_new/lib:./lib -pkg-sources moonbitlang/core:$MOON_HOME/lib/core -target native -cc cc -cc-flags "-I$MOON_HOME/include -fno-strict-aliasing ccflags fasd" -cc-link-flags cclinkflags ./target/native/release/build/lib/lib.exe ./target/native/release/build/main/main.exe @@ -8311,11 +8310,8 @@ fn test_moon_install_bin() { assert!(_4.exists()); assert!(_5.exists()); - let output = get_stderr(&dir, ["build", "--sort-input"]); - - #[cfg(unix)] check( - &output, + get_stderr(&dir, ["build", "--sort-input"]), expect![[r#" main-js lib Hello, world! @@ -8324,12 +8320,6 @@ fn test_moon_install_bin() { Finished. moon: ran 17 tasks, now up to date "#]], ); - - #[cfg(windows)] - { - assert!(output.contains("main-js")); - assert!(output.contains("lib Hello, world!")); - } } #[test] diff --git a/crates/moonutil/src/common.rs b/crates/moonutil/src/common.rs index 4df46cbc..f5c65dec 100644 --- a/crates/moonutil/src/common.rs +++ b/crates/moonutil/src/common.rs @@ -882,7 +882,7 @@ impl StringExt for str { pub fn set_native_backend_link_flags( run_mode: RunMode, - _release: bool, + release: bool, target_backend: Option, module: &mut crate::module::ModuleDB, ) -> anyhow::Result<()> { @@ -896,11 +896,10 @@ pub fn set_native_backend_link_flags( #[cfg(windows)] let compiler = "cl"; - let _ = - which::which(compiler).context(format!("{} not found in PATH", compiler))?; 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"); // libmoonbitrun.o should under $MOON_HOME/lib let libmoonbitrun_path = moon_home.join("lib").join("libmoonbitrun.o"); @@ -944,12 +943,29 @@ pub fn set_native_backend_link_flags( .or(get_default_cc_flags()), cc_link_flags: n.cc_link_flags.clone().or(get_default_cc_link_flag()), }, - None => crate::package::NativeLinkConfig { + None if release => crate::package::NativeLinkConfig { exports: None, cc: Some(compiler.to_string()), cc_flags: get_default_cc_flags(), cc_link_flags: get_default_cc_link_flag(), }, + None => crate::package::NativeLinkConfig { + exports: None, + cc: Some( + moon_home + .join("bin") + .join("internal") + .join("tcc") + .display() + .to_string(), + ), + cc_flags: Some(format!( + "-L{} -I{} -DMOONBIT_NATIVE_NO_SYS_HEADER", + moon_lib_path.display(), + moon_include_path.display() + )), + cc_link_flags: None, + }, }; pkg.link = Some(crate::package::Link {