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
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ default-members = ["./crates/*"]
rust-version = "1.80"
edition = "2021"

[workspace.features]
moongres = [
"moon/moongres",
"moonbuild/moongres",
"moonbuild-rupes-recta/moongres",
"moonutil/moongres",
]

[workspace.dependencies]
n2 = { git = "https://github.com/moonbitlang/n2.git", rev = "2cb2af63170acf3852c61326d5883a71f3576615" }
arcstr = { version = "1.2", features = ["serde"] }
Expand Down
7 changes: 7 additions & 0 deletions crates/moon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
moongres = [
"moonbuild/moongres",
"moonbuild-rupes-recta/moongres",
"moonutil/moongres",
]

[dependencies]
moonbuild.workspace = true
mooncake.workspace = true
Expand Down
8 changes: 8 additions & 0 deletions crates/moon/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ fn run_single_mbt_file(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Resu
TargetBackend::Wasm | TargetBackend::WasmGC => {
println!("moonrun {}", output_wasm_or_js_path.display());
}
#[cfg(feature = "moongres")]
TargetBackend::MoonGRES => {
println!("rustica-engine run {}", output_wasm_or_js_path.display());
}
TargetBackend::Js => {
println!("node {}", output_wasm_or_js_path.display());
}
Expand Down Expand Up @@ -304,6 +308,10 @@ fn run_single_mbt_file(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Resu
TargetBackend::Wasm | TargetBackend::WasmGC => {
moonbuild::build::run_wat(&output_wasm_or_js_path, &cmd.args, cli.verbose)
}
#[cfg(feature = "moongres")]
TargetBackend::MoonGRES => {
moonbuild::build::run_moongres(&output_wasm_or_js_path, &cmd.args, cli.verbose)
}
TargetBackend::Js => {
moonbuild::build::run_js(&output_wasm_or_js_path, &cmd.args, cli.verbose)
}
Expand Down
20 changes: 19 additions & 1 deletion crates/moon/src/run/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use tokio::process::Command;

macro_rules! cache {
($(
$(#[$attr:meta])*
$id:ident(
$first_candidate:expr
$(,$candidate:expr)* $(,)?
Expand All @@ -39,12 +40,14 @@ macro_rules! cache {
#[derive(Default)]
pub struct RuntimeExecutableCache {
$(
$(#[$attr])*
$id: OnceCell<PathBuf>
),*
}

impl RuntimeExecutableCache {
$(
$(#[$attr])*
pub fn $id(&self) -> &Path {
self.$id.get_or_init(|| {
which::which($first_candidate)
Expand All @@ -59,7 +62,9 @@ macro_rules! cache {

cache! {
node("node", "node.cmd"),
moonrun("moonrun")
moonrun("moonrun"),
#[cfg(feature = "moongres")]
rustica_engine("rustica-engine", "rustica-engine.exe"),
}

/// A guarded command info that removes the temporary file/dir(s) when it gets
Expand Down Expand Up @@ -119,6 +124,19 @@ pub fn command_for_cached(
cmd.arg("--");
Ok(cmd.into())
}
#[cfg(feature = "moongres")]
TargetBackend::MoonGRES => {
let mut cmd = Command::new(cache.rustica_engine());
if let Some(t) = test {
cmd.arg("moontest")
.arg("--spec")
.arg(serde_json::to_string(t).expect("valid test args"));
} else {
cmd.arg("run");
}
cmd.arg(mbt_executable).arg("--");
Ok(cmd.into())
}
TargetBackend::Js => {
if let Some(t) = test {
let (dir, driver) = create_js_driver(mbt_executable, t)?;
Expand Down
3 changes: 3 additions & 0 deletions crates/moonbuild-rupes-recta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ version = "0.1.0"
rust-version.workspace = true
edition.workspace = true

[features]
moongres = [ "moonutil/moongres" ]

[dependencies]
moonutil.workspace = true
mooncake.workspace = true
Expand Down
8 changes: 8 additions & 0 deletions crates/moonbuild-rupes-recta/src/build_lower/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ fn linked_core_artifact_ext(
match backend {
TargetBackend::Wasm | TargetBackend::WasmGC if wasm_use_wat => ".wat",
TargetBackend::Wasm | TargetBackend::WasmGC => ".wasm",
#[cfg(feature = "moongres")]
TargetBackend::MoonGRES if wasm_use_wat => ".wat",
#[cfg(feature = "moongres")]
TargetBackend::MoonGRES => ".wasm",
TargetBackend::Js => ".js",
TargetBackend::Native => ".c",
TargetBackend::LLVM => object_file_ext(os),
Expand All @@ -353,6 +357,10 @@ fn make_executable_artifact_ext(
match backend {
TargetBackend::Wasm | TargetBackend::WasmGC if wasm_use_wat => ".wat",
TargetBackend::Wasm | TargetBackend::WasmGC => ".wasm",
#[cfg(feature = "moongres")]
TargetBackend::MoonGRES if wasm_use_wat => ".wat",
#[cfg(feature = "moongres")]
TargetBackend::MoonGRES => ".wasm",
TargetBackend::Js => ".js",
TargetBackend::Native | TargetBackend::LLVM => executable_ext(os, legacy_behavior),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ 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
3 changes: 3 additions & 0 deletions crates/moonbuild/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
moongres = [ "moonutil/moongres" ]

[dependencies]
arcstr.workspace = true
moonutil.workspace = true
Expand Down
14 changes: 14 additions & 0 deletions crates/moonbuild/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ pub fn run_wat(path: &Path, args: &[String], verbose: bool) -> anyhow::Result<()
run(cmd, verbose)
}

#[cfg(feature = "moongres")]
pub fn run_moongres(path: &Path, args: &[String], verbose: bool) -> anyhow::Result<()> {
let mut cmd = Command::new(
crate::RUSTICA_ENGINE_EXECUTABLE
.as_deref()
.context("Unable to find the `rustica-engine` executable, please reinstall")?,
);
cmd.arg("run").arg(path);
if !args.is_empty() {
cmd.arg("--").args(args);
}
run(cmd, verbose)
}

pub fn run_js(path: &Path, args: &[String], verbose: bool) -> anyhow::Result<()> {
let mut cmd = Command::new(
NODE_EXECUTABLE
Expand Down
2 changes: 2 additions & 0 deletions crates/moonbuild/src/dry_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub fn print_run_commands(
let mut watfile = state.graph.file(*fid).name.clone();
let cmd = match target_backend {
TargetBackend::Wasm | TargetBackend::WasmGC => "moonrun ",
#[cfg(feature = "moongres")]
TargetBackend::MoonGRES => "rustica-engine run ",
TargetBackend::Js => "node ",
TargetBackend::Native | TargetBackend::LLVM => {
// stub.o would be default for native and llvm, skip them
Expand Down
15 changes: 15 additions & 0 deletions crates/moonbuild/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,10 @@ pub fn run_run(
TargetBackend::Wasm | TargetBackend::WasmGC => {
crate::build::run_wat(&wat_path, &moonbuild_opt.args, moonbuild_opt.verbose)
}
#[cfg(feature = "moongres")]
TargetBackend::MoonGRES => {
crate::build::run_moongres(&wat_path, &moonbuild_opt.args, moonbuild_opt.verbose)
}
TargetBackend::Js => {
crate::build::run_js(&wat_path, &moonbuild_opt.args, moonbuild_opt.verbose)
}
Expand Down Expand Up @@ -968,6 +972,17 @@ async fn execute_test(
crate::runtest::run_wat(artifact_path, target_dir, args, file_test_info_map, verbose)
.await
}
#[cfg(feature = "moongres")]
TargetBackend::MoonGRES => {
crate::runtest::run_moongres(
artifact_path,
target_dir,
args,
file_test_info_map,
verbose,
)
.await
}
TargetBackend::Js => {
crate::runtest::run_js(
&artifact_path.with_extension("cjs"),
Expand Down
2 changes: 2 additions & 0 deletions crates/moonbuild/src/gen/gen_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,8 @@ pub fn gen_n2_build_state(
let runtime = match moonc_opt.link_opt.target_backend {
TargetBackend::Native | TargetBackend::LLVM => "".to_string(),
TargetBackend::Wasm | TargetBackend::WasmGC => "moonrun".to_string(),
#[cfg(feature = "moongres")]
TargetBackend::MoonGRES => "rustica-engine run".to_string(),
TargetBackend::Js => "node".to_string(),
};

Expand Down
18 changes: 18 additions & 0 deletions crates/moonbuild/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,21 @@ static PYTHON_EXECUTABLE: LazyLock<Option<std::path::PathBuf>> = LazyLock::new(|
.iter()
.find_map(|name| which::which(name).ok())
});
#[cfg(feature = "moongres")]
static RUSTICA_ENGINE_EXECUTABLE: LazyLock<Option<std::path::PathBuf>> = LazyLock::new(|| {
let candidates = ["rustica-engine.exe", "rustica-engine"];
// Prefer the one next to the current executable
if let Ok(current_exe) = std::env::current_exe() {
if let Some(exe_dir) = current_exe.parent() {
let rv = candidates
.iter()
.map(|exe| exe_dir.join(exe))
.find(|p| p.exists());
if rv.is_some() {
return rv;
}
}
}
// Fallback to search in PATH
candidates.iter().find_map(|exe| which::which(exe).ok())
});
20 changes: 20 additions & 0 deletions crates/moonbuild/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ pub async fn run_wat(
run(path, cmd, target_dir, file_test_info_map, verbose).await
}

#[cfg(feature = "moongres")]
pub async fn run_moongres(
path: &Path,
target_dir: &Path,
args: &TestArgs,
file_test_info_map: &FileTestInfo,
verbose: bool,
) -> anyhow::Result<Vec<Result<TestStatistics, TestFailedStatus>>> {
let mut cmd = tokio::process::Command::new(
crate::RUSTICA_ENGINE_EXECUTABLE
.as_deref()
.context("Unable to find the `rustica-engine` executable, please reinstall")?,
);
cmd.arg("moontest")
.arg("--spec")
.arg(serde_json_lenient::to_string(args).expect("valid JSON"))
.arg(path);
run(path, cmd, target_dir, file_test_info_map, verbose).await
}

pub async fn run_js(
path: &Path,
target_dir: &Path,
Expand Down
3 changes: 3 additions & 0 deletions crates/moonutil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
moongres = []

[dependencies]
arcstr.workspace = true
home.workspace = true
Expand Down
Loading
Loading