Skip to content

Commit 32e4068

Browse files
authored
fix: cdk use preferred target for compatibility for default build target (#4168)
1 parent acf2f94 commit 32e4068

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

crates/cdk/src/build.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashMap;
12
use std::fmt::Debug;
23

34
use anyhow::Result;
@@ -21,7 +22,13 @@ pub struct BuildCmd {
2122

2223
impl BuildCmd {
2324
pub(crate) fn process(self) -> Result<()> {
24-
let opt = self.package.as_opt();
25+
let mut opt = self.package.as_opt();
26+
if target_not_specified() {
27+
let tmap = Self::target_map();
28+
if let Some(tgt) = tmap.get(&opt.target.as_str()) {
29+
opt.target = tgt.to_string();
30+
}
31+
}
2532
let package_info = PackageInfo::from_options(&opt)?;
2633

2734
build_connector(
@@ -32,4 +39,16 @@ impl BuildCmd {
3239
},
3340
)
3441
}
42+
43+
/// Map to most supported native target
44+
fn target_map() -> HashMap<&'static str, &'static str> {
45+
let mut map = HashMap::new();
46+
map.insert("x86_64-unknown-linux-musl", "x86_64-unknown-linux-gnu");
47+
map
48+
}
49+
}
50+
51+
fn target_not_specified() -> bool {
52+
let args = std::env::args().collect::<Vec<String>>();
53+
!args.iter().any(|arg| arg.contains("--target"))
3554
}

0 commit comments

Comments
 (0)