fix: split target into target (triple) and out_dir (output directory)

build.target now holds the target triple (e.g. x86_64-unknown-linux-gnu)
build.out_dir is a custom output directory that overrides the default
target/<triple>/<profile> path.
This commit is contained in:
2026-05-30 14:18:54 +08:00
parent 0587965283
commit 865d8c52ff
7 changed files with 352 additions and 40 deletions

View File

@@ -119,6 +119,8 @@ pub struct BuildConfig {
#[serde(default)]
pub target: Option<String>,
#[serde(default)]
pub out_dir: Option<String>,
#[serde(default)]
pub platform: Option<String>,
#[serde(default)]
pub cflags: Vec<String>,
@@ -396,6 +398,9 @@ impl Config {
if let Some(target) = &build.target {
validate_non_empty_string(target, "build.target")?;
}
if let Some(out_dir) = &build.out_dir {
validate_non_empty_string(out_dir, "build.out_dir")?;
}
for profile in ["release", "debug"] {
if let Some(section) = self
.data
@@ -539,7 +544,9 @@ impl Config {
if let Some(lang) = table.get("language") {
self.validate_language(lang)?;
}
for key in ["standard", "compiler", "kind", "target", "platform"] {
for key in [
"standard", "compiler", "kind", "target", "out_dir", "platform",
] {
if let Some(value) = table.get(key) {
let s = value.as_str().unwrap_or("");
if s.trim().is_empty() {
@@ -784,6 +791,11 @@ fn format_toml(value: &Value) -> Result<String, ConfigError> {
{
out.push_str(&format!("target = \"{target}\"\n"));
}
if let Some(out_dir) = build.get("out_dir").and_then(|v| v.as_str())
&& !out_dir.trim().is_empty()
{
out.push_str(&format!("out_dir = \"{out_dir}\"\n"));
}
if let Some(cflags) = build.get("cflags") {
out.push_str(&format!("cflags = {}\n", format_string_array(cflags)));
}