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

Add support for configuring xwin using env vars #1961

Merged
merged 1 commit into from Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/compile.rs
Expand Up @@ -11,7 +11,7 @@ use std::collections::HashMap;
use std::env;
use std::io::{BufReader, Read};
use std::path::{Path, PathBuf};
use std::process::Stdio;
use std::process::{Command, Stdio};
use std::str;
use tracing::{debug, trace};

Expand Down Expand Up @@ -141,16 +141,17 @@ fn compile_targets(
) -> Result<Vec<HashMap<String, BuildArtifact>>> {
let mut artifacts = Vec::with_capacity(targets.len());
for target in targets {
artifacts.push(compile_target(context, python_interpreter, target)?);
let build_command = cargo_build_command(context, python_interpreter, target)?;
artifacts.push(compile_target(context, build_command)?);
}
Ok(artifacts)
}

fn compile_target(
fn cargo_build_command(
context: &BuildContext,
python_interpreter: Option<&PythonInterpreter>,
compile_target: &CompileTarget,
) -> Result<HashMap<String, BuildArtifact>> {
) -> Result<Command> {
let target = &context.target;

let mut cargo_rustc: cargo_options::Rustc = context.cargo_options.clone().into();
Expand Down Expand Up @@ -281,9 +282,17 @@ fn compile_target(
let mut build_command = if target.is_msvc() && target.cross_compiling() {
#[cfg(feature = "xwin")]
{
let mut build = cargo_xwin::Rustc::from(cargo_rustc);
let xwin_options = {
use clap::Parser;

// This will populate the default values for the options
// and then override them with cargo-xwin environment variables.
cargo_xwin::XWinOptions::parse_from(Vec::<&str>::new())
};

let mut build = cargo_xwin::Rustc::from(cargo_rustc);
build.target = vec![target_triple.to_string()];
build.xwin = xwin_options;
build.build_command()?
}
#[cfg(not(feature = "xwin"))]
Expand Down Expand Up @@ -444,7 +453,13 @@ fn compile_target(
};
build_command.env("MACOSX_DEPLOYMENT_TARGET", deployment_target);
}
Ok(build_command)
}

fn compile_target(
context: &BuildContext,
mut build_command: Command,
) -> Result<HashMap<String, BuildArtifact>> {
debug!("Running {:?}", build_command);

let using_cross = build_command
Expand Down