Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting the nightly flag -Zmultitarget #19

Merged
merged 24 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6ba9e80
Modified target to be a vector of multiple possible target hosts
TheOnlyArtz Mar 23, 2022
34c063e
Cargo fmt
TheOnlyArtz Mar 23, 2022
b736f9d
Not using options since it's unnecessary
TheOnlyArtz Mar 23, 2022
3626c56
Add macOS `SDKROOT` support
messense Mar 23, 2022
bcee417
Merge pull request #20 from messense/sdkroot
messense Mar 23, 2022
d56275e
Bump version to 0.6.8
messense Mar 23, 2022
fd71c5d
Binding each linker to it's desired target
TheOnlyArtz Mar 24, 2022
9764da5
Lowercased CC linkers
TheOnlyArtz Mar 24, 2022
355ab77
Target should stay uppercased
TheOnlyArtz Mar 24, 2022
8a3f2f3
LINKER should stay uppercased
TheOnlyArtz Mar 24, 2022
82ee218
Tet x86_64 glibc 2.17 run on CentOS 7
messense Mar 24, 2022
3c9675e
Modified target to be a vector of multiple possible target hosts
TheOnlyArtz Mar 23, 2022
274be51
Cargo fmt
TheOnlyArtz Mar 23, 2022
651d414
Not using options since it's unnecessary
TheOnlyArtz Mar 23, 2022
265886f
Binding each linker to it's desired target
TheOnlyArtz Mar 24, 2022
27fc4ce
Lowercased CC linkers
TheOnlyArtz Mar 24, 2022
b8e24b7
Target should stay uppercased
TheOnlyArtz Mar 24, 2022
d49c1ce
LINKER should stay uppercased
TheOnlyArtz Mar 24, 2022
6166534
Removed target redundancy
TheOnlyArtz Mar 24, 2022
9d3f49e
preserving raw targets when needed
TheOnlyArtz Mar 24, 2022
19ca895
Merge after rebase resolution
TheOnlyArtz Mar 24, 2022
ad29abe
Providing zig linker with raw target
TheOnlyArtz Mar 24, 2022
8809154
Zipping parsed and raw
TheOnlyArtz Mar 24, 2022
e35dfe9
fmt
TheOnlyArtz Mar 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ pub struct Build {
pub no_default_features: bool,

/// Build for the target triple
#[clap(long, value_name = "TRIPLE", env = "CARGO_BUILD_TARGET")]
pub target: Option<String>,
#[clap(
long,
value_name = "TRIPLE",
env = "CARGO_BUILD_TARGET",
multiple_occurrences = true
)]
pub target: Vec<String>,

/// Directory for all generated artifacts
#[clap(long, value_name = "DIRECTORY", parse(from_os_str))]
Expand Down Expand Up @@ -190,10 +195,10 @@ impl Build {
let mut build = Command::new("cargo");
build.arg(subcommand);

let rust_target = self
let rust_targets = self
.target
.as_ref()
.map(|target| target.split_once('.').map(|(t, _)| t).unwrap_or(target));
.iter()
.map(|target| target.split_once('.').map(|(t, _)| t).unwrap_or(&target));

// collect cargo build arguments
if self.quiet {
Expand Down Expand Up @@ -259,9 +264,11 @@ impl Build {
if self.no_default_features {
build.arg("--no-default-features");
}
if let Some(rust_target) = rust_target {
build.arg("--target").arg(&rust_target);
}

rust_targets.for_each(|target| {
build.arg("--target").arg(&target);
});

if let Some(dir) = self.target_dir.as_ref() {
build.arg("--target-dir").arg(dir);
}
Expand Down Expand Up @@ -310,14 +317,15 @@ impl Build {

if !self.disable_zig_linker {
// setup zig as linker
if let Some(target) = self.target.as_ref() {
let rustc_meta = rustc_version::version_meta()?;
let host_target = &rustc_meta.host;
// we only setup zig as linker when target isn't exactly the same as host target
if host_target != target {
TheOnlyArtz marked this conversation as resolved.
Show resolved Hide resolved
if let Some(rust_target) = rust_target {
let rustc_meta = rustc_version::version_meta()?;
let host_target = &rustc_meta.host;
// we only setup zig as linker when target isn't exactly the same as host target

for (i, full_target) in self.target.iter().enumerate() {
if host_target != full_target {
if let Some(rust_target) = self.target.get(i) {
let env_target = rust_target.to_uppercase().replace('-', "_");
let (zig_cc, zig_cxx) = prepare_zig_linker(target)?;
let (zig_cc, zig_cxx) = prepare_zig_linker(full_target)?;
if is_mingw_shell() {
let zig_cc = zig_cc.to_slash_lossy();
build.env("TARGET_CC", &zig_cc);
messense marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -351,7 +359,7 @@ impl Build {
}

fn setup_os_deps(&self) -> Result<()> {
if let Some(target) = self.target.as_ref() {
for target in &self.target {
if target.contains("apple") {
let target_dir = if let Some(target_dir) = self.target_dir.clone() {
target_dir.join(target)
Expand Down
9 changes: 7 additions & 2 deletions src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ pub struct Rustc {
pub no_default_features: bool,

/// Build for the target triple
#[clap(long, value_name = "TRIPLE", env = "CARGO_BUILD_TARGET")]
pub target: Option<String>,
#[clap(
long,
value_name = "TRIPLE",
env = "CARGO_BUILD_TARGET",
multiple_occurrences = true
)]
pub target: Vec<String>,

/// Output compiler information without compiling
#[clap(long, value_name = "INFO")]
Expand Down