Custom output directory via build.target

This commit is contained in:
2026-02-23 13:51:53 +08:00
parent e0fd729635
commit cb8a3b2001
15 changed files with 91 additions and 31 deletions

View File

@@ -37,8 +37,11 @@ pub fn build(ctx: &BuildContext) -> Result<f64, String> {
for flag in ctx.ldflags {
cmd.arg(flag);
}
cmd.arg("-o")
.arg(platform::bin_path(ctx.profile, ctx.project_name));
cmd.arg("-o").arg(platform::bin_path(
ctx.profile,
ctx.project_name,
ctx.target_dir,
));
match cmd.status() {
Ok(status) if status.success() => {

View File

@@ -37,8 +37,11 @@ pub fn build(ctx: &BuildContext) -> Result<f64, String> {
for flag in ctx.ldflags {
cmd.arg(flag);
}
cmd.arg("-o")
.arg(platform::bin_path(ctx.profile, ctx.project_name));
cmd.arg("-o").arg(platform::bin_path(
ctx.profile,
ctx.project_name,
ctx.target_dir,
));
match cmd.status() {
Ok(status) if status.success() => {

View File

@@ -8,6 +8,7 @@ pub struct BuildContext<'a> {
pub compiler: &'a str,
pub language: &'a str,
pub standard: &'a str,
pub target_dir: Option<&'a str>,
pub include_dirs: &'a [String],
pub lib_dirs: &'a [String],
pub libs: &'a [String],

View File

@@ -63,7 +63,7 @@ pub fn build(ctx: &BuildContext) -> Result<f64, String> {
}
cmd.arg(format!(
"/Fe:{}",
platform::bin_path(ctx.profile, ctx.project_name)
platform::bin_path(ctx.profile, ctx.project_name, ctx.target_dir)
));
match cmd.status() {

View File

@@ -216,16 +216,19 @@ fn format_toml(value: &Value) -> Result<String, ConfigError> {
out.push_str("[build]\n");
out.push_str(&format!("language = \"{language}\"\n"));
out.push_str(&format!("standard = \"{standard}\"\n"));
out.push_str(&format!("compiler = \"{compiler}\"\n\n"));
out.push_str(&format!("compiler = \"{compiler}\"\n"));
if let Some(target) = build.get("target").and_then(|v| v.as_str()) {
if !target.trim().is_empty() {
out.push_str(&format!("target = \"{target}\"\n"));
}
}
if let Some(cflags) = build.get("cflags") {
out.push_str(&format!("cflags = {}\n", format_string_array(cflags)));
}
if let Some(ldflags) = build.get("ldflags") {
out.push_str(&format!("ldflags = {}\n", format_string_array(ldflags)));
}
if build.contains_key("cflags") || build.contains_key("ldflags") {
out.push('\n');
}
out.push('\n');
out.push_str("[dependencies]\n");
if !deps.is_empty() {