Skip to content

Commit

Permalink
internal: support --enable-value-tracing for build-package
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash committed Dec 26, 2024
1 parent fcc35b4 commit ba87d4a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
5 changes: 5 additions & 0 deletions crates/moon/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ pub struct BuildFlags {
/// Alert list config
#[clap(long, allow_hyphen_values = true)]
pub alert_list: Option<String>,

/// Enable value tracing
#[clap(long, hide = true)]
pub enable_value_tracing: bool,
}

impl BuildFlags {
Expand Down Expand Up @@ -262,6 +266,7 @@ pub fn get_compiler_flags(src_dir: &Path, build_flags: &BuildFlags) -> anyhow::R
target_backend,
warn_list: build_flags.warn_list.clone(),
alert_list: build_flags.alert_list.clone(),
enable_value_tracing: build_flags.enable_value_tracing,
};

let link_opt = LinkCoreFlags {
Expand Down
38 changes: 22 additions & 16 deletions crates/moon/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,25 @@ fn run_single_mbt_file(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Resu
output_artifact_path.join(format!("{}.{}", file_name, target_backend.to_extension()));

let pkg_name = "moon/run/single";
let build_package_command = [
"build-package",
&mbt_file_path.display().to_string(),
"-o",
output_core_path,
"-std-path",
core_bundle_path.to_str().unwrap(),
"-is-main",
"-pkg",
pkg_name,
"-g",
"-O0",
"-source-map",
"-target",
target_backend.to_flag(),
let mut build_package_command = vec![
"build-package".to_string(),
mbt_file_path.display().to_string(),
"-o".to_string(),
output_core_path.to_string(),
"-std-path".to_string(),
core_bundle_path.to_str().unwrap().to_string(),
"-is-main".to_string(),
"-pkg".to_string(),
pkg_name.to_string(),
"-g".to_string(),
"-O0".to_string(),
"-source-map".to_string(),
"-target".to_string(),
target_backend.to_flag().to_string(),
];
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)
Expand Down Expand Up @@ -167,7 +170,7 @@ fn run_single_mbt_file(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Resu
}

let moonc_build_package = std::process::Command::new("moonc")
.args(build_package_command)
.args(&build_package_command)
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.spawn()?
Expand Down Expand Up @@ -295,6 +298,9 @@ pub fn run_run_internal(cli: &UniversalFlags, cmd: RunSubcommand) -> anyhow::Res
&dir_sync_result,
)?;

let pkg = module.get_package_by_path_mut(&package).unwrap();
pkg.enable_value_tracing = cmd.build_flags.enable_value_tracing;

moonutil::common::set_native_backend_link_flags(
run_mode,
cmd.build_flags.release,
Expand Down
3 changes: 3 additions & 0 deletions crates/moonbuild/src/gen/gen_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct BuildDepItem {
pub alert_list: Option<String>,
pub is_main: bool,
pub is_third_party: bool,
pub enable_value_tracing: bool,
}

type BuildLinkDepItem = moonutil::package::LinkDepItem;
Expand Down Expand Up @@ -118,6 +119,7 @@ pub fn gen_build_build_item(
alert_list: pkg.alert_list.clone(),
is_main: pkg.is_main,
is_third_party: pkg.is_third_party,
enable_value_tracing: pkg.enable_value_tracing,
})
}

Expand Down Expand Up @@ -246,6 +248,7 @@ pub fn gen_build_command(

let command = CommandBuilder::new("moonc")
.arg("build-package")
.arg_with_cond(item.enable_value_tracing, "-enable-value-tracing")
.args_with_cond(moonc_opt.render, vec!["-error-format", "json"])
.args_with_cond(
moonc_opt.build_opt.deny_warn,
Expand Down
2 changes: 2 additions & 0 deletions crates/moonutil/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ pub struct BuildPackageFlags {
pub target_backend: TargetBackend,
pub warn_list: Option<String>,
pub alert_list: Option<String>,
pub enable_value_tracing: bool,
}

impl BuildPackageFlags {
Expand All @@ -329,6 +330,7 @@ impl BuildPackageFlags {
target_backend: TargetBackend::default(),
warn_list: None,
alert_list: None,
enable_value_tracing: false,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/moonutil/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub struct Package {
pub bin_name: Option<String>,

pub bin_target: TargetBackend,

pub enable_value_tracing: bool,
}

impl Package {
Expand Down
1 change: 1 addition & 0 deletions crates/moonutil/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ fn scan_one_package(
.filter(|_| pkg.is_main && !is_third_party),
bin_name: pkg.bin_name,
bin_target: pkg.bin_target,
enable_value_tracing: false,
};
if doc_mode {
// -o <folder>
Expand Down

0 comments on commit ba87d4a

Please sign in to comment.