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

Read host target triple from rustc -vV #487

Merged
merged 2 commits into from
Apr 8, 2021
Merged

Conversation

messense
Copy link
Member

@messense messense commented Apr 5, 2021

Fixes #478, closes #486

cc @al626

@messense messense force-pushed the target_env branch 2 times, most recently from ea7ecde to d8c3016 Compare April 5, 2021 13:34
@konstin
Copy link
Member

konstin commented Apr 5, 2021

I think the best solution for both maturin build --target xxx --universal2 from #429 and the musl handling from #478 would be reverting #429 and manually failing on the --target xxx --universal2 case. I.e. I'd prefer #486 and add an extra error path. This also has the advantage that we save a subprocess call.

If there are other reasons I've missing and we still need to go for reading the target triple, I'd do what cargo does and read rustc -vV:

use std::process::Command;

use anyhow::{format_err, Context, Result};
use std::str;

fn get_target() -> Result<String> {
    let output = Command::new("rustc")
        .arg("-vV")
        .output()
        .context("Failed to run rustc to get the host target")?;
    let output = str::from_utf8(&output.stdout).context("`rustc -vV` didn't return utf8 output")?;

    let field = "host: ";
    let host = output
        .lines()
        .find(|l| l.starts_with(field))
        .map(|l| &l[field.len()..])
        .ok_or_else(|| {
            format_err!(
                "`rustc -vV` didn't have a line for `{}`, got:\n{}",
                field.trim(),
                output
            )
        })?
        .to_string();
    Ok(host)
}

fn main() -> Result<()> {
    let host = get_target()?;
    println!("target triple: {}", host);
    Ok(())
}

@messense
Copy link
Member Author

messense commented Apr 5, 2021

There is also #423 affected by target_env

@messense messense changed the title Get target_env from rustc --print cfg Read host target triple from rustc -vV Apr 5, 2021
@messense
Copy link
Member Author

messense commented Apr 5, 2021

Anyway I think it's good to get rid of Platform::guess_current(). Reading the host target triple from rustc is a better solution than using inaccuratePlatform::guess_current() IMO.

uses: actions-rs/cargo@v1
with:
command: test
args: --target x86_64-unknown-linux-musl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're only shipping musl anyway, wouldn't it make more sense to only run the tests for musl?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case someone needs to compile maturin from source instead of using prebuilt wheels, for example on some BSD systems?

Copy link
Member

@konstin konstin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strange behavior with PyPy in 0.10 prerelease
3 participants