Skip to content

Commit

Permalink
fix: cdk use preferred target for compatibility for default build tar…
Browse files Browse the repository at this point in the history
…get (#4168)
  • Loading branch information
digikata authored Sep 6, 2024
1 parent acf2f94 commit 32e4068
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion crates/cdk/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::fmt::Debug;

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

impl BuildCmd {
pub(crate) fn process(self) -> Result<()> {
let opt = self.package.as_opt();
let mut opt = self.package.as_opt();
if target_not_specified() {
let tmap = Self::target_map();
if let Some(tgt) = tmap.get(&opt.target.as_str()) {
opt.target = tgt.to_string();
}
}
let package_info = PackageInfo::from_options(&opt)?;

build_connector(
Expand All @@ -32,4 +39,16 @@ impl BuildCmd {
},
)
}

/// Map to most supported native target
fn target_map() -> HashMap<&'static str, &'static str> {
let mut map = HashMap::new();
map.insert("x86_64-unknown-linux-musl", "x86_64-unknown-linux-gnu");
map
}
}

fn target_not_specified() -> bool {
let args = std::env::args().collect::<Vec<String>>();
!args.iter().any(|arg| arg.contains("--target"))
}

0 comments on commit 32e4068

Please sign in to comment.