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

Clean up libc-test/build.rs for FreeBSD and enable testing FreeBSD12 on CI #1346

Merged
merged 2 commits into from
May 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 20 additions & 7 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
freebsd_instance:
image: freebsd-11-1-release-amd64

task:
# This name gets reported as a build status in GitHub
name: stable x86_64-unknown-freebsd
name: stable x86_64-unknown-freebsd-11
freebsd_instance:
image: freebsd-11-2-release-amd64
setup_script:
- pkg install -y curl
- curl https://sh.rustup.rs -sSf --output rustup.sh
- sh rustup.sh -y
- . $HOME/.cargo/env
- rustup default stable
test_script:
- . $HOME/.cargo/env
- sh ci/run.sh x86_64-unknown-freebsd

task:
name: nightly x86_64-unknown-freebsd-12
freebsd_instance:
image: freebsd-12-0-release-amd64
setup_script:
- pkg install -y curl
- curl https://sh.rustup.rs -sSf --output rustup.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

This invocation will install both nightly and stable toolchains. It would be faster just to install nightly. I haven't tested it, but I think you could do it like this:

- curl https://sh.rustup.rs -sSf --output rustup.sh
- sh rustup.sh --default-toolchain nightly -y

- sh rustup.sh --default-toolchain nightly -y
- . $HOME/.cargo/env
- rustup default nightly
test_script:
- . $HOME/.cargo/env
- cd libc-test
- cargo test
- sh ci/run.sh x86_64-unknown-freebsd
29 changes: 29 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ fn main() {
);
}

if std::env::var("LIBC_CI").is_ok() {
if let Some(12) = which_freebsd() {
println!("cargo:rustc-cfg=freebsd12");
}
}

// Rust >= 1.15 supports private module use:
if rustc_minor_ver >= 15 || rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_priv_mod_use");
Expand Down Expand Up @@ -70,3 +76,26 @@ fn rustc_minor_version() -> Option<u32> {

otry!(pieces.next()).parse().ok()
}

fn which_freebsd() -> Option<i32> {
let output = std::process::Command::new("freebsd-version").output().ok();
Copy link
Contributor

Choose a reason for hiding this comment

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

Easier to use uname -U, which will return a purely numeric output like 1102000. The first two digits are the major version number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does uname -U fail if the system is not FreeBSD, but say, DragonflyBSD ? The reason I used freebsd-version is that I wanted something that's guaranteed to fail if the host is not FreeBSD.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, good point. Dragonfly's man page doesn't mention -U.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, apple doesn't have uname -U either; it appears to be FreeBSD specific. Somehow I am a bit more comfortable with freebsd-version, but I don't mind much either way as long as its reliable enough for libc's CI, which is under our control.

We might want to revisit this issue when we start exploring how to expose this capability to users.

if output.is_none() {
return None;
}
let output = output.unwrap();
if !output.status.success() {
return None;
}

let stdout = String::from_utf8(output.stdout).ok();
if stdout.is_none() {
return None;
}
let stdout = stdout.unwrap();

match &stdout {
s if s.starts_with("11") => Some(11),
s if s.starts_with("12") => Some(12),
_ => None,
}
}
8 changes: 5 additions & 3 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ if [ "$TARGET" = "x86_64-unknown-linux-gnux32" ]; then
opt="--release"
fi

cargo test $opt --no-default-features --manifest-path libc-test/Cargo.toml \
export LIBC_CI=1

cargo test -vv $opt --no-default-features --manifest-path libc-test/Cargo.toml \
--target "${TARGET}"

cargo test $opt --manifest-path libc-test/Cargo.toml --target "${TARGET}"
cargo test -vv $opt --manifest-path libc-test/Cargo.toml --target "${TARGET}"

cargo test $opt --features extra_traits --manifest-path libc-test/Cargo.toml \
cargo test -vv $opt --features extra_traits --manifest-path libc-test/Cargo.toml \
--target "${TARGET}"
Loading