Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion crates/moon/src/cli/generate_test_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ const COMMON_TEMPLATE: &str = include_str!(concat!(
"/../moonbuild/template/test_driver/common.mbt"
));

#[cfg(feature = "moongres")]
const MOONGRES_BENCH_DRIVER_TEMPLATE: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../moonbuild/template/test_driver/moongres/bench_driver_template.mbt"
));

#[cfg(feature = "moongres")]
const MOONGRES_TEST_DRIVER_TEMPLATE: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../moonbuild/template/test_driver/moongres/test_driver_template.mbt"
));

fn generate_driver(
data: &MooncGenTestInfo,
pkgname: &str,
Expand All @@ -246,7 +258,13 @@ fn generate_driver(
TEST_DRIVER_TEMPLATE
};
let mut template = template.to_string();
if !enable_bench {
if enable_bench {
#[cfg(feature = "moongres")]
template.push_str(MOONGRES_BENCH_DRIVER_TEMPLATE);
} else {
#[cfg(feature = "moongres")]
template.push_str(MOONGRES_TEST_DRIVER_TEMPLATE);

if only_no_arg_tests {
template.push_str(NO_ARGS_TEMPLATE)
} else {
Expand Down
24 changes: 18 additions & 6 deletions crates/moon/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ fn run_single_mbt_file(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Resu
};

if cli.dry_run {
println!("moonc {}", build_package_command.join(" "));
println!("moonc {}", link_core_command.join(" "));
println!(
"{} {}",
target_backend.moonc(),
build_package_command.join(" ")
);
println!("{} {}", target_backend.moonc(), link_core_command.join(" "));
if let Some(compile_exe_command) = compile_exe_command {
println!("{}", compile_exe_command.join(" "));
}
Expand All @@ -258,26 +262,34 @@ fn run_single_mbt_file(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Resu
return Ok(0);
}

let moonc_build_package = std::process::Command::new("moonc")
let moonc_build_package = std::process::Command::new(target_backend.moonc())
.args(&build_package_command)
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.spawn()?
.wait()?;

if !moonc_build_package.success() {
bail!("failed to run: moonc {}", build_package_command.join(" "))
bail!(
"failed to run: {} {}",
target_backend.moonc(),
build_package_command.join(" ")
)
}

let moonc_link_core = std::process::Command::new("moonc")
let moonc_link_core = std::process::Command::new(target_backend.moonc())
.args(&link_core_command)
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.spawn()?
.wait()?;

if !moonc_link_core.success() {
bail!("failed to run: moonc {}", link_core_command.join(" "))
bail!(
"failed to run: {} {}",
target_backend.moonc(),
link_core_command.join(" ")
)
}

if let Some(compile_exe_command) = compile_exe_command {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@ impl<'a> CmdlineAbstraction for MoonGenTestDriver<'a> {
// Configuration
args.extend([
"--target".to_string(),
// TODO(xenia): remove this after compiler support
#[cfg(feature = "moongres")]
match (args.first().map(|s| s.as_str()), self.target_backend) {
(Some("moon"), TargetBackend::MoonGRES) => "moongres".to_string(),
_ => self.target_backend.to_flag().to_string(),
},
#[cfg(not(feature = "moongres"))]
self.target_backend.to_flag().to_string(),
]);
args.extend(["--pkg-name".to_string(), self.pkg_name.to_string()]);
Expand Down
2 changes: 1 addition & 1 deletion crates/moonbuild-rupes-recta/src/build_lower/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use std::path::PathBuf;

use log::debug;
use moonutil::{common::TargetBackend, cond_expr::OptLevel, mooncakes::result::ResolvedEnv};
use moonutil::{cond_expr::OptLevel, mooncakes::result::ResolvedEnv};
use n2::graph::{Build, Graph as N2Graph};

use crate::{
Expand Down
8 changes: 4 additions & 4 deletions crates/moonbuild-rupes-recta/src/build_lower/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<'a> BuildPlanLowerContext<'a> {

BuildCommand {
extra_inputs: files_vec.clone(),
commandline: cmd.build_command("moonc"),
commandline: cmd.build_command(self.opt.target_backend.moonc()),
}
}

Expand Down Expand Up @@ -149,7 +149,7 @@ impl<'a> BuildPlanLowerContext<'a> {
// TODO: a lot of knobs are not controlled here

BuildCommand {
commandline: cmd.build_command("moonc"),
commandline: cmd.build_command(self.opt.target_backend.moonc()),
extra_inputs: files,
}
}
Expand Down Expand Up @@ -228,7 +228,7 @@ impl<'a> BuildPlanLowerContext<'a> {

BuildCommand {
extra_inputs: vec![],
commandline: cmd.build_command("moonc"),
commandline: cmd.build_command(self.opt.target_backend.moonc()),
}
}

Expand Down Expand Up @@ -476,7 +476,7 @@ impl<'a> BuildPlanLowerContext<'a> {

BuildCommand {
extra_inputs: vec![],
commandline: cmd.build_command("moonc"),
commandline: cmd.build_command(self.opt.target_backend.moonc()),
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/moonbuild/src/gen/gen_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ pub fn gen_build_interface_command(

let mut build = Build::new(loc, ins, outs);

let command = CommandBuilder::new("moonc")
let command = CommandBuilder::new(moonc_opt.build_opt.target_backend.moonc())
.arg("build-interface")
.arg(&item.mbti_deps)
.arg("-o")
Expand Down Expand Up @@ -505,7 +505,7 @@ pub fn gen_build_command(
moonc_opt.build_opt.strip_flag,
);

let command = CommandBuilder::new("moonc")
let command = CommandBuilder::new(moonc_opt.build_opt.target_backend.moonc())
.arg("build-package")
.args_with_cond(moonc_opt.render, vec!["-error-format", "json"])
.args_with_cond(
Expand Down Expand Up @@ -638,7 +638,7 @@ pub fn gen_link_command(
moonc_opt.build_opt.strip_flag,
);

let command = CommandBuilder::new("moonc")
let command = CommandBuilder::new(moonc_opt.link_opt.target_backend.moonc())
.arg("link-core")
.args(&item.core_deps)
.arg("-main")
Expand Down
6 changes: 3 additions & 3 deletions crates/moonbuild/src/gen/gen_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pub fn gen_build_command(
moonc_opt.build_opt.strip_flag,
);

let command = CommandBuilder::new("moonc")
let command = CommandBuilder::new(moonc_opt.build_opt.target_backend.moonc())
.arg("build-package")
.args_with_cond(moonc_opt.render, vec!["-error-format", "json"])
.args(&item.mbt_deps)
Expand Down Expand Up @@ -258,7 +258,7 @@ fn gen_bundle_all(
graph: &mut n2graph::Graph,
bundle_all: &N2BundleAll,
target_dir: &Path,
_moonc_opt: &MooncOpt,
moonc_opt: &MooncOpt,
) -> Build {
let loc = FileLoc {
filename: Rc::new(PathBuf::from("bundle")),
Expand Down Expand Up @@ -290,7 +290,7 @@ fn gen_bundle_all(

let mut build = Build::new(loc, ins, outs);

let command = CommandBuilder::new("moonc")
let command = CommandBuilder::new(moonc_opt.build_opt.target_backend.moonc())
.arg("bundle-core")
.args(bundle_all.order.iter())
.arg("-o")
Expand Down
2 changes: 1 addition & 1 deletion crates/moonbuild/src/gen/gen_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ pub fn gen_check_command(

let mut build = Build::new(loc, ins, outs);

let command = CommandBuilder::new("moonc")
let command = CommandBuilder::new(moonc_opt.build_opt.target_backend.moonc())
.arg("check")
.arg_with_cond(item.patch_file.is_some(), "-patch-file")
.lazy_args_with_cond(item.patch_file.is_some(), || {
Expand Down
4 changes: 2 additions & 2 deletions crates/moonbuild/src/gen/gen_runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ pub fn gen_runtest_build_command(
moonc_opt.build_opt.strip_flag,
);

let command = CommandBuilder::new("moonc")
let command = CommandBuilder::new(moonc_opt.build_opt.target_backend.moonc())
.arg("build-package")
.args_with_cond(moonc_opt.render, vec!["-error-format", "json"])
.args(&item.mbt_deps)
Expand Down Expand Up @@ -1311,7 +1311,7 @@ pub fn gen_runtest_link_command(
moonc_opt.build_opt.strip_flag,
);

let command = CommandBuilder::new("moonc")
let command = CommandBuilder::new(moonc_opt.link_opt.target_backend.moonc())
.arg("link-core")
.args(&item.core_deps)
.arg("-main")
Expand Down
2 changes: 1 addition & 1 deletion crates/moonbuild/template/test_driver/common.mbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn moonbit_test_driver_internal_error_to_string(x : Error) -> String = "%error.to_string"

#cfg(not(target="js"))
#cfg(not(any(target="js", target="moongres")))
fn moonbit_unsafe_char_from_int(x : Int) -> Char = "%identity"

#cfg(target="native")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#cfg(target="moongres")
pub fn moonbit_test_driver_internal_execute(filename : String, index : Int) -> Unit {
moonbit_test_driver_internal_do_execute(filename, index)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#cfg(target="moongres")
pub fn moonbit_test_driver_internal_execute(filename : String, index : Int) -> Unit {
moonbit_test_driver_internal_run_async_main(fn(ctx) {
moonbit_test_driver_internal_do_execute(ctx, filename, index)
})
}
11 changes: 10 additions & 1 deletion crates/moonutil/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ pub enum TargetBackend {
#[default]
WasmGC,
#[cfg(feature = "moongres")]
#[value(name = "moongres")]
MoonGRES,
Js,
Native,
Expand All @@ -322,7 +323,7 @@ impl TargetBackend {
Self::Wasm => "wasm",
Self::WasmGC => "wasm-gc",
#[cfg(feature = "moongres")]
Self::MoonGRES => "wasm-gc", // TODO(xenia): change to moongres after compiler support
Self::MoonGRES => "moongres",
Self::Js => "js",
Self::Native => "native",
Self::LLVM => "llvm",
Expand Down Expand Up @@ -438,6 +439,14 @@ impl TargetBackend {
}
}

pub fn moonc(self) -> &'static str {
match self {
#[cfg(feature = "moongres")]
Self::MoonGRES => "mgresc",
_ => "moonc",
}
}

pub fn all() -> &'static [Self] {
Self::value_variants()
}
Expand Down