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
6 changes: 3 additions & 3 deletions crates/moon/src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ fn calc_user_intent(
.packages_for_module(main_module_id)
.ok_or_else(|| anyhow!("Cannot find the local module!"))?;
let linkable_pkgs =
get_linkable_pkgs(resolve_output, target_backend, packages.values().cloned())?;
get_linkable_pkgs(resolve_output, target_backend, packages.values().cloned());
let intents: Vec<_> = if linkable_pkgs.is_empty() {
packages
.iter()
Expand All @@ -250,7 +250,7 @@ fn get_linkable_pkgs(
resolve_output: &moonbuild_rupes_recta::ResolveOutput,
target_backend: TargetBackend,
packages: impl Iterator<Item = PackageId>,
) -> anyhow::Result<Vec<PackageId>> {
) -> Vec<PackageId> {
let mut linkable_pkgs = vec![];
for pkg_id in packages {
let pkg = resolve_output.pkg_dirs.get_package(pkg_id);
Expand All @@ -265,5 +265,5 @@ fn get_linkable_pkgs(
linkable_pkgs.push(pkg_id)
}
}
Ok(linkable_pkgs)
linkable_pkgs
}
13 changes: 5 additions & 8 deletions crates/moon/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,7 @@ fn run_run_rr(
}

#[instrument(level = Level::DEBUG, skip_all)]
fn get_run_cmd(
build_meta: &rr_build::BuildMeta,
argv: &[String],
) -> Result<tokio::process::Command, anyhow::Error> {
fn get_run_cmd(build_meta: &rr_build::BuildMeta, argv: &[String]) -> tokio::process::Command {
let (_, artifact) = build_meta
.artifacts
.first()
Expand All @@ -161,9 +158,9 @@ fn get_run_cmd(
.artifacts
.first()
.expect("Expected exactly one executable as the output of the build node");
let mut cmd = crate::run::command_for(build_meta.target_backend, executable, None)?;
let mut cmd = crate::run::command_for(build_meta.target_backend, executable, None);
cmd.args(argv);
Ok(cmd)
cmd
}

#[instrument(level = Level::DEBUG, skip_all)]
Expand Down Expand Up @@ -307,7 +304,7 @@ fn rr_run_from_plan(
target_dir,
);

let run_cmd = get_run_cmd(build_meta, &cmd.args)?;
let run_cmd = get_run_cmd(build_meta, &cmd.args);
rr_build::dry_print_command(run_cmd.as_std(), source_dir, false);
return Ok(0);
}
Expand All @@ -323,7 +320,7 @@ fn rr_run_from_plan(
if !build_result.successful() {
return Ok(build_result.return_code_for_success());
}
let run_cmd = get_run_cmd(build_meta, &cmd.args)?;
let run_cmd = get_run_cmd(build_meta, &cmd.args);
if cli.verbose {
rr_build::dry_print_command(run_cmd.as_std(), source_dir, true);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/moon/src/cli/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ pub(crate) fn run_tool(cli: &UniversalFlags, cmd: ToolSubcommand) -> anyhow::Res
ToolSubcommands::BuildBinaryDep(subcmd) => {
build_binary_dep::run_build_binary_dep(cli, &subcmd)
}
ToolSubcommands::Demangle(subcmd) => run_demangle(subcmd),
ToolSubcommands::Demangle(subcmd) => Ok(run_demangle(subcmd)),
}
}
8 changes: 4 additions & 4 deletions crates/moon/src/cli/tool/build_binary_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub(crate) fn run_build_binary_dep(
.pkg_dirs
.packages_for_module(main_module_id)
.ok_or_else(|| anyhow::anyhow!("Cannot find the local module!"))?;
get_linkable_pkgs_for_bin_dep(&resolve_output, packages.values().cloned(), default_backend)?
get_linkable_pkgs_for_bin_dep(&resolve_output, packages.values().cloned(), default_backend)
} else {
let mut result_pkgs = vec![];
for pkg_name in cmd.pkg_names.iter() {
Expand Down Expand Up @@ -165,15 +165,15 @@ fn get_linkable_pkgs_for_bin_dep(
resolve_output: &moonbuild_rupes_recta::ResolveOutput,
packages: impl Iterator<Item = PackageId>,
default_backend: TargetBackend,
) -> anyhow::Result<Vec<(PackageId, TargetBackend)>> {
) -> Vec<(PackageId, TargetBackend)> {
let mut linkable_pkgs = vec![];
for pkg_id in packages {
let pkg = resolve_output.pkg_dirs.get_package(pkg_id);
let pkg_bin_target = pkg.raw.bin_target.unwrap_or(default_backend);

add_bin_dep(&mut linkable_pkgs, pkg_id, pkg, pkg_bin_target);
}
Ok(linkable_pkgs)
linkable_pkgs
}

fn add_bin_dep(
Expand Down Expand Up @@ -213,7 +213,7 @@ fn install_build_rr(
.context("RR build should yield exactly one artifact file")?;

// Build command using existing runtime mapping, then shlex-join
let guard = crate::run::command_for(meta.target_backend, artifact, None)?;
let guard = crate::run::command_for(meta.target_backend, artifact, None);
let parts = std::iter::once(guard.as_std().get_program())
.chain(guard.as_std().get_args())
.map(|x| x.to_string_lossy().to_string())
Expand Down
4 changes: 2 additions & 2 deletions crates/moon/src/cli/tool/demangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ pub(crate) struct DemangleSubcommand {
names: Vec<String>,
}

pub(crate) fn run_demangle(cmd: DemangleSubcommand) -> anyhow::Result<i32> {
pub(crate) fn run_demangle(cmd: DemangleSubcommand) -> i32 {
for name in cmd.names {
println!(
"{}",
moonutil::demangle::demangle_mangled_function_name(&name)
);
}
Ok(0)
0
}
2 changes: 1 addition & 1 deletion crates/moon/src/run/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ fn run_one_test_executable(
ctx.build_meta.target_backend,
test.executable,
Some(&test_args),
)?;
);
let mut cov_cap = mk_coverage_capture();
let mut test_cap = make_test_capture();
if ctx.verbose {
Expand Down
12 changes: 6 additions & 6 deletions crates/moon/src/run/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) fn command_for(
backend: RunBackend,
mbt_executable: &Path,
test: Option<&TestArgs>,
) -> anyhow::Result<Command> {
) -> Command {
match backend {
RunBackend::Wasm | RunBackend::WasmGC => {
let mut cmd = Command::new(&*moonutil::BINARIES.moonrun);
Expand All @@ -54,7 +54,7 @@ pub(crate) fn command_for(
}
cmd.arg(mbt_executable);
cmd.arg("--");
Ok(cmd)
cmd
}
RunBackend::Js => {
if let Some(t) = test {
Expand All @@ -68,19 +68,19 @@ pub(crate) fn command_for(
cmd.arg("--enable-source-maps");
cmd.arg(mbt_executable);
cmd.arg(serde_json::to_string(t).expect("Failed to serialize test args"));
Ok(cmd)
cmd
} else {
let mut cmd = Command::new(moonutil::BINARIES.node_or_default());
cmd.arg(mbt_executable);
Ok(cmd)
cmd
}
}
RunBackend::Native | RunBackend::Llvm => {
let mut cmd = Command::new(mbt_executable);
if let Some(t) = test {
cmd.arg(t.to_cli_args_for_native());
}
Ok(cmd)
cmd
}
RunBackend::NativeTccRun => {
let tcc = CC::internal_tcc().expect("TCC must be available for TCC run backend");
Expand All @@ -89,7 +89,7 @@ pub(crate) fn command_for(
if let Some(t) = test {
cmd.arg(t.to_cli_args_for_native());
}
Ok(cmd)
cmd
}
}
}
1 change: 1 addition & 0 deletions crates/moon/tests/test_cases/native_abort_trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;

#[cfg(unix)]
#[test]
#[ignore = "TODO: this doesn't work on CI for unknown reason"]
fn test_native_abort_trace() {
const ANSI_LINE_NUMBER_REGEX: &str = r"(?<redacted>:[0-9]+)(?:(?:\x1b\[[0-9;]*m)|(?:\[ANSI_[A-Z]+\]))*(?:[ \t]+(?:(?:\x1b\[[0-9;]*m)|(?:\[ANSI_[A-Z]+\]))*(?:at|by)|\n|$)";
let dir = TestDir::new("native_abort_trace/native_abort_trace.in");
Expand Down
20 changes: 6 additions & 14 deletions crates/moonbuild-rupes-recta/src/discover/special_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ use crate::special_cases::CORE_MODULE_TUPLE;
use moonutil::mooncakes::result::ResolvedEnv;
use tracing::{info, instrument, warn};

use crate::{
discover::{DiscoverError, DiscoverResult},
pkg_name::PackagePath,
};
use crate::{discover::DiscoverResult, pkg_name::PackagePath};

/// Inject `moonbitlang/core/coverage` contents into `moonbitlang/core/builtin`
/// so builtin is effectively augmented with coverage sources during discovery.
Expand All @@ -32,10 +29,7 @@ use crate::{
/// downstream compilation/linking sees coverage alongside builtin without
/// additional per-target import wiring.
#[instrument(skip_all)]
pub fn inject_core_coverage_into_builtin(
env: &ResolvedEnv,
res: &mut DiscoverResult,
) -> Result<(), DiscoverError> {
pub fn inject_core_coverage_into_builtin(env: &ResolvedEnv, res: &mut DiscoverResult) {
// Only proceed if we have a stdlib module locally
let Some(&stdlib) = env
.input_module_ids()
Expand All @@ -45,25 +39,25 @@ pub fn inject_core_coverage_into_builtin(
info!(
"No standard library injected and no local core module found, skipping coverage->builtin injection"
);
return Ok(());
return;
};

// Resolve coverage and builtin package ids within stdlib module
let Some(map) = res.packages_for_module(stdlib) else {
// No packages for stdlib; nothing to do
return Ok(());
return;
};

let builtin_path = PackagePath::new("builtin").expect("builtin is a valid package path");
let coverage_path = PackagePath::new("coverage").expect("coverage is a valid package path");

let Some(&builtin_id) = map.get(&builtin_path) else {
warn!("No builtin package found in core module, skipping coverage->builtin injection");
return Ok(());
return;
};
let Some(&coverage_id) = map.get(&coverage_path) else {
warn!("No coverage package found in core module, skipping coverage->builtin injection");
return Ok(());
return;
};

// Clone coverage source files into builtin
Expand All @@ -73,6 +67,4 @@ pub fn inject_core_coverage_into_builtin(
// Merge .mbt source files
builtin.source_files.extend(coverage_files);
builtin.source_files.sort();

Ok(())
}
2 changes: 1 addition & 1 deletion crates/moonbuild-rupes-recta/src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pub fn resolve(cfg: &ResolveConfig, source_dir: &Path) -> Result<ResolveOutput,
};
if cfg.enable_coverage && main_is_core {
// Gate coverage bundling (coverage -> builtin) behind both flag and main-module check
inject_core_coverage_into_builtin(&resolved_env, &mut discover_result)?;
inject_core_coverage_into_builtin(&resolved_env, &mut discover_result);
}

info!(
Expand Down
16 changes: 8 additions & 8 deletions crates/moonbuild/src/expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ struct Replace {
}

impl Replace {
fn guess_target(&self) -> anyhow::Result<Target> {
fn guess_target(&self) -> Target {
// trivial case where content is provided, we can get precise location
if let Some(loc) = &self.expect_loc {
Ok(Target {
Target {
left_border_line_start: self.loc.line_start,
left_border_col_start: self.loc.col_start,
line_start: loc.line_start,
Expand All @@ -256,11 +256,11 @@ impl Replace {
expect: self.expect.clone(),
actual: self.actual.clone(),
mode: self.mode.clone(),
})
}
} else {
let is_pipe = self.actual_loc.ahead(&self.loc);
if is_pipe {
Ok(Target {
Target {
left_border_line_start: self.loc.line_start,
left_border_col_start: self.loc.col_start,
line_start: self.loc.line_end,
Expand All @@ -271,10 +271,10 @@ impl Replace {
expect: self.expect.clone(),
actual: self.actual.clone(),
mode: self.mode.clone(),
})
}
} else {
// TODO: find comma
Ok(Target {
Target {
left_border_line_start: self.actual_loc.line_end,
left_border_col_start: self.actual_loc.col_end,

Expand All @@ -286,7 +286,7 @@ impl Replace {
expect: self.expect.clone(),
actual: self.actual.clone(),
mode: self.mode.clone(),
})
}
}
}
}
Expand Down Expand Up @@ -415,7 +415,7 @@ fn collect<'a>(
targets
.entry(rep.loc.filename.clone())
.or_default()
.insert(rep.guess_target()?);
.insert(rep.guess_target());
}
Ok(targets)
}
Expand Down
7 changes: 3 additions & 4 deletions crates/moonrun/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,12 @@ fn run_interactive() -> anyhow::Result<()> {
}
}

fn initialize_v8() -> anyhow::Result<()> {
fn initialize_v8() {
v8::V8::set_flags_from_string("--experimental-wasm-exnref");
v8::V8::set_flags_from_string("--experimental-wasm-imported-strings");
let platform = v8::new_default_platform(0, false).make_shared();
v8::V8::initialize_platform(platform);
v8::V8::initialize();
Ok(())
}

fn main() -> anyhow::Result<()> {
Expand All @@ -595,7 +594,7 @@ fn main() -> anyhow::Result<()> {
let matches = Commandline::parse();

if matches.interactive {
initialize_v8()?;
initialize_v8();
run_interactive()
} else {
let file = matches.path.as_ref().unwrap();
Expand All @@ -610,7 +609,7 @@ fn main() -> anyhow::Result<()> {

match file.extension().unwrap().to_str() {
Some("wasm") => {
initialize_v8()?;
initialize_v8();
wasm_mode(
Source::File(file),
&matches.args,
Expand Down