Skip to content

Commit

Permalink
Merge pull request #2 from alexcrichton/freebsd
Browse files Browse the repository at this point in the history
Freebsd
  • Loading branch information
alexcrichton committed Sep 19, 2015
2 parents 751b42e + 22f3c5e commit fa3f6e7
Show file tree
Hide file tree
Showing 23 changed files with 1,314 additions and 1,494 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,17 @@ various systems, including libc.
[![Build status](https://ci.appveyor.com/api/projects/status/v0414slj8y8nga0p?svg=true)](https://ci.appveyor.com/project/alexcrichton/libc)

[Documentation](http://alexcrichton.com/libc)

## Platform Support

Tested:
* `{i686,x86_64}-pc-windows-{msvc,gnu}`
* `{i686,x86_64,mips,aarch64}-unknown-linux-gnu`
* `x86_64-unknown-linux-musl`
* `arm-unknown-linux-gnueabihf`
* `arm-linux-androideabi`
* `{i686,x86_64}-apple-darwin`

Untested:
* `{i686,x86_64}-unknown-freebsd`
* `x86_64-unknown-{bitrig,dragonfly,openbsd,netbsd}`
4 changes: 4 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ build: false
test_script:
- cargo test
- cargo run --manifest-path libc-test/Cargo.toml

branches:
only:
- autotest
38 changes: 38 additions & 0 deletions ci/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# A vagrant configuration file for running tests on BSD-like machines
#
# Note that this was originally intended to later be used to run tests on
# Travis, but it didn't work out. Regardless this has stuck around! You can run
# tests in FreeBSD via:
#
# git clone https://github.com/alexcrichton/libc --branch autotest
# cd libc/ci
# vagrant up freebsd
# vagrant ssh freebsd
# ...
# cd /vagrant/libc-test
# cargo run
#
# And "that's it"! You look up instructions on Vagrant's website for how to
# install vagrant.

Vagrant.configure(2) do |config|
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

config.vm.synced_folder "..", "/vagrant"

config.vm.define :freebsd do |bsd|
bsd.vm.box = "arkadi/freebsd-10.1-amd64"
bsd.vm.provision :shell, inline: 'yes | sudo pkg install rust cargo'
bsd.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
end

config.vm.define :openbsd do |bsd|
bsd.vm.box = "bodgit/openbsd-5.7-amd64"
bsd.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
end
end
103 changes: 58 additions & 45 deletions ci/run-travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,65 @@ install() {
sudo apt-get install $@
}

if [ "$TARGET" = "arm-linux-androideabi" ]; then
case "$TARGET" in
# Pull a pre-built docker image for testing android, then run tests entirely
# within that image.
docker pull alexcrichton/rust-libc-test
exec docker run -v `pwd`:/clone -t alexcrichton/rust-libc-test \
sh ci/run.sh $TARGET
elif [ "$TARGET" = "x86_64-unknown-linux-musl" ]; then
curl -s $EXTRA_TARGETS/$TARGET.tar.gz | tar xzf - -C $HOME/rust/lib/rustlib
install musl-tools
export CC=musl-gcc
elif [ "$TARGET" = "arm-unknown-linux-gnueabihf" ]; then
curl -s $EXTRA_TARGETS/$TARGET.tar.gz | tar xzf - -C $HOME/rust/lib/rustlib
install gcc-4.7-arm-linux-gnueabihf qemu-user
export CC=arm-linux-gnueabihf-gcc-4.7
elif [ "$TARGET" = "aarch64-unknown-linux-gnu" ]; then
curl -s $EXTRA_TARGETS/$TARGET.tar.gz | tar xzf - -C $HOME/rust/lib/rustlib
install gcc-aarch64-linux-gnu qemu-user
export CC=aarch64-linux-gnu-gcc
elif [ "$TARGET" = "mips-unknown-linux-gnu" ]; then
# Download pre-built and custom MIPS libs and then also instsall the MIPS
# compiler according to this post:
# http://sathisharada.blogspot.com/2014_10_01_archive.html
curl -s $EXTRA_TARGETS/$TARGET.tar.gz | tar xzf - -C $HOME/rust/lib/rustlib

echo 'deb http://ftp.de.debian.org/debian squeeze main' | \
sudo tee -a /etc/apt/sources.list
echo 'deb http://www.emdebian.org/debian/ squeeze main' | \
sudo tee -a /etc/apt/sources.list
install emdebian-archive-keyring
install qemu-user gcc-4.4-mips-linux-gnu -y --force-yes
export CC=mips-linux-gnu-gcc
else
# Download the rustlib folder from the relevant portion of main distribution's
# tarballs.
curl -s $MAIN_TARGETS/rust-$TRAVIS_RUST_VERSION-$HOST.tar.gz | \
tar xzf - -C $HOME/rust/lib/rustlib --strip-components=4 \
rust-$TRAVIS_RUST_VERSION-$HOST/rustc/lib/rustlib/$HOST
TARGET=$HOST

# clang has better error messages and implements alignof more broadly
export CC=clang

if [ "$TARGET" = "i686-unknown-linux-gnu" ]; then
install gcc-multilib
fi
fi
#d within that image.
arm-linux-androideabi)
docker pull alexcrichton/rust-libc-test
exec docker run -v `pwd`:/clone -t alexcrichton/rust-libc-test \
sh ci/run.sh $TARGET
;;

x86_64-unknown-linux-musl)
curl -s $EXTRA_TARGETS/$TARGET.tar.gz | tar xzf - -C $HOME/rust/lib/rustlib
install musl-tools
export CC=musl-gcc
;;

arm-unknown-linux-gnueabihf)
curl -s $EXTRA_TARGETS/$TARGET.tar.gz | tar xzf - -C $HOME/rust/lib/rustlib
install gcc-4.7-arm-linux-gnueabihf qemu-user
export CC=arm-linux-gnueabihf-gcc-4.7
;;

aarch64-unknown-linux-gnu)
curl -s $EXTRA_TARGETS/$TARGET.tar.gz | tar xzf - -C $HOME/rust/lib/rustlib
install gcc-aarch64-linux-gnu qemu-user
export CC=aarch64-linux-gnu-gcc
;;

mips-unknown-linux-gnu)
# Download pre-built and custom MIPS libs and then also instsall the MIPS
# compiler according to this post:
# http://sathisharada.blogspot.com/2014_10_01_archive.html
curl -s $EXTRA_TARGETS/$TARGET.tar.gz | tar xzf - -C $HOME/rust/lib/rustlib

echo 'deb http://ftp.de.debian.org/debian squeeze main' | \
sudo tee -a /etc/apt/sources.list
echo 'deb http://www.emdebian.org/debian/ squeeze main' | \
sudo tee -a /etc/apt/sources.list
install emdebian-archive-keyring
install qemu-user gcc-4.4-mips-linux-gnu -y --force-yes
export CC=mips-linux-gnu-gcc
;;

*)
# Download the rustlib folder from the relevant portion of main distribution's
# tarballs.
curl -s $MAIN_TARGETS/rust-$TRAVIS_RUST_VERSION-$HOST.tar.gz | \
tar xzf - -C $HOME/rust/lib/rustlib --strip-components=4 \
rust-$TRAVIS_RUST_VERSION-$HOST/rustc/lib/rustlib/$HOST
TARGET=$HOST

# clang has better error messages and implements alignof more broadly
export CC=clang

if [ "$TARGET" = "i686-unknown-linux-gnu" ]; then
install gcc-multilib
fi
;;

esac

mkdir .cargo
cp ci/cargo-config .cargo/config
Expand Down
29 changes: 19 additions & 10 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,28 @@ set -ex
TARGET=$1
cargo build --manifest-path libc-test/Cargo.toml --target $TARGET

if [ "$TARGET" = "arm-linux-androideabi" ]; then
case "$TARGET" in
arm-linux-androideabi)
emulator @test -no-window &
adb wait-for-device
adb push /root/target/$TARGET/debug/libc-test /data/libc-test
adb shell /data/libc-test
elif [ "$TARGET" = "arm-unknown-linux-gnueabihf" ]; then
;;

arm-unknown-linux-gnueabihf)
qemu-arm -L /usr/arm-linux-gnueabihf libc-test/target/$TARGET/debug/libc-test
elif [ "$TARGET" = "mips-unknown-linux-gnu" ]; then
# FIXME: this segfaults on travis, passes locally?
#qemu-mips -L /usr/mips-linux-gnu libc-test/target/$TARGET/debug/all-*
echo skip
elif [ "$TARGET" = "aarch64-unknown-linux-gnu" ]; then
qemu-aarch64 -L /usr/aarch64-linux-gnu/ libc-test/target/$TARGET/debug/libc-test
else
;;

mips-unknown-linux-gnu)
qemu-mips -L /usr/mips-linux-gnu libc-test/target/$TARGET/debug/libc-test
;;

aarch64-unknown-linux-gnu)
qemu-aarch64 -L /usr/aarch64-linux-gnu/ \
libc-test/target/$TARGET/debug/libc-test
;;

*)
cargo run --manifest-path libc-test/Cargo.toml --target $TARGET
fi
;;
esac
57 changes: 29 additions & 28 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ fn main() {
let android = target.contains("android");
let darwin = target.contains("apple-darwin");
let musl = target.contains("musl");
let freebsd = target.contains("freebsd");
let bsdlike = freebsd || darwin;
let mut cfg = ctest::TestGenerator::new();

// Pull in extra goodies on linux/mingw
Expand Down Expand Up @@ -39,14 +41,6 @@ fn main() {
.header("time.h")
.header("wchar.h");

if darwin {
cfg.header("mach-o/dyld.h");
cfg.header("mach/mach_time.h");
} else if linux || android {
cfg.header("netpacket/packet.h");
cfg.header("net/ethernet.h");
}

if windows {
cfg.header("winsock2.h"); // must be before windows.h

Expand Down Expand Up @@ -84,31 +78,38 @@ fn main() {
cfg.header("utime.h");
cfg.header("pwd.h");
cfg.header("grp.h");
}

if android {
cfg.header("arpa/inet.h");
} else {
cfg.header("glob.h");
cfg.header("ifaddrs.h");

if !musl {
cfg.header("execinfo.h");
cfg.header("sys/sysctl.h");
}
}

if darwin {
cfg.header("malloc/malloc.h");
cfg.header("crt_externs.h");
} else {
cfg.header("malloc.h");
if android {
cfg.header("arpa/inet.h");
} else if !windows {
cfg.header("glob.h");
cfg.header("ifaddrs.h");

if !musl {
cfg.header("execinfo.h");
cfg.header("sys/sysctl.h");
}
}

if darwin {
cfg.header("mach-o/dyld.h");
cfg.header("mach/mach_time.h");
cfg.header("malloc/malloc.h");
cfg.header("crt_externs.h");
}
if target.contains("linux") {

if linux || android {
cfg.header("netpacket/packet.h");
cfg.header("net/ethernet.h");
cfg.header("malloc.h");
cfg.header("sys/prctl.h");
}

if freebsd {
cfg.header("pthread_np.h");
}

cfg.type_name(move |ty, is_struct| {
match ty {
// Just pass all these through, no need for a "struct" prefix
Expand All @@ -120,7 +121,7 @@ fn main() {
"ssize_t" if windows => "SSIZE_T".to_string(),

// OSX calls this something else
"sighandler_t" if darwin => "sig_t".to_string(),
"sighandler_t" if bsdlike => "sig_t".to_string(),

t if t.ends_with("_t") => t.to_string(),

Expand Down Expand Up @@ -216,7 +217,7 @@ fn main() {
"strerror_r" if linux => true, // actually xpg-something-or-other

// typed 2nd arg on linux and android
"gettimeofday" if linux || android => true,
"gettimeofday" if linux || android || freebsd => true,

"dlerror" if android => true, // const-ness is added

Expand Down
Loading

0 comments on commit fa3f6e7

Please sign in to comment.