Skip to content

Commit 032f363

Browse files
committed
Merge pull request rust-lang#21 from alexcrichton/master
Implement RFC 1291 changes
2 parents 452cee5 + 2995f55 commit 032f363

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+5330
-32
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/target
2-
/Cargo.lock
1+
target
2+
Cargo.lock

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

.travis.yml

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
11
language: rust
2-
sudo: false
3-
before_install:
4-
- git submodule update --init --recursive
2+
sudo: required
3+
rust:
4+
- 1.0.0
5+
- beta
6+
- nightly
7+
services:
8+
- docker
59
script:
6-
- cargo build --verbose
7-
- cargo doc --verbose
8-
after_success: |
9-
[ $TRAVIS_BRANCH = master ] &&
10-
[ $TRAVIS_PULL_REQUEST = false ] &&
11-
echo '<meta http-equiv=refresh content=0;url=libc/index.html>' > target/doc/index.html &&
12-
pip install ghp-import --user $USER &&
13-
$HOME/.local/bin/ghp-import -n target/doc &&
14-
git push -fq https://${TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
15-
10+
- sh ci/run-travis.sh
11+
os:
12+
- linux
13+
- osx
1614
env:
15+
matrix:
16+
- ARCH=x86_64
17+
- ARCH=i686
1718
global:
18-
secure: MZGg+symX6/fcY7TsQ1LkJ28V/CUevNZgs3MiilgvnlgTjqn7BU7gbTvwhLdVZq04/EQ1hTeVzrFGpBfcCUVHYKmP2vooEFJJ+bDGEvyD8ChwCB4nV+NmxF5+NwCi3+Y+0pBgKbt2BasJ+MXkGJpRyFozis6loMWbXTzZzL9jjU=
19+
secure: knGy4XLi5DVpZPcBaB8PiGA49NtZLcaWwLIPwSS68CwRJXOeeNPe/+xb7vWCWblJp3k7jK1HkJgHq+muWe1e+gUvXpmvASyuwpIBd4eQn55k4jfQlAVPCpxoIYANnv7bjfDMhuTEUDmvt9vI7BXDlLfi2VRrSrUd9obSwd3QU+ie5V88FTvPIe12zVmcvW8YVkKYsWRM4auIOU7CZSEW4nT+OE6RCpETE12u1qxUhsq03byCL7HQYGJs2S0RsqdyEZV+kAeJxA0ULNXlPs0FEagpqFbxfmZSSWzGp6K9juaRc03OBYiCcxrhYopuU1B1q4xMJk/2xWfPhoNJTU8yKW6fHstJz9Eb7MXH2y3UzDBAbDdwaNH4/aq0fN6O2U2lr7n09oF+pa9Gi5gyUYhKN19skaHMPF+Y7GCkqyCpR2oKTWTp+zSKycvgcsfl9zX2MvZG2NCgLPqRPaCEg/Psa2HvnM4/LgZw5ViDHJDVvNofzKx+2zzUlpsrkXaVDeRqUYVnO/LLiLl1cVT0QDHH1DHLXFY8G7CLfQYA64Np0LURartCmoamC86FavkSPTmnUL7i3RBMJnOUy2Uzf/SzbdRq3Sfp5tAV/miGzWaJFs81wuDKTWq5bnSGNVR18Wori6K8BboRYLmxMpSgQJ/8AnvnXETKwoP2lajJr1A4oPI=
20+
matrix:
21+
include:
22+
- os: linux
23+
env: TARGET=arm-linux-androideabi
24+
rust: nightly
25+
- os: linux
26+
env: TARGET=x86_64-unknown-linux-musl
27+
rust: nightly
28+
- os: linux
29+
env: TARGET=arm-unknown-linux-gnueabihf
30+
rust: nightly
31+
- os: linux
32+
env: TARGET=mips-unknown-linux-gnu
33+
rust: nightly
34+
- os: linux
35+
env: TARGET=aarch64-unknown-linux-gnu
36+
rust: nightly
37+
- os: osx
38+
env: TARGET=i386-apple-ios
39+
rust: nightly-2015-09-08
40+
- os: osx
41+
env: TARGET=x86_64-apple-ios
42+
rust: nightly-2015-09-08
1943
notifications:
2044
email:
2145
on_success: never
46+
branches:
47+
only:
48+
- master

Cargo.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ description = """
1212
A library for types and bindings to native C functions often found in libc or
1313
other common platform libraries.
1414
"""
15-
include = ["Cargo.toml", "rust/src/liblibc/*"]
1615

1716
[features]
18-
default = ["cargo-build"]
19-
cargo-build = []
20-
21-
[lib]
22-
name = "libc"
23-
path = "rust/src/liblibc/lib.rs"
17+
default = []

README.md

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,112 @@ A Rust library with native bindings to the types and functions commonly found on
55
various systems, including libc.
66

77
[![Build Status](https://travis-ci.org/rust-lang/libc.svg?branch=master)](https://travis-ci.org/rust-lang/libc)
8+
[![Build status](https://ci.appveyor.com/api/projects/status/v0414slj8y8nga0p?svg=true)](https://ci.appveyor.com/project/alexcrichton/libc)
89

9-
[Documentation](http://doc.rust-lang.org/libc)
10+
[Documentation](#platforms-and-documentation)
1011

1112
## Usage
1213

13-
Add this to your `Cargo.toml`:
14+
First, add the following to your `Cargo.toml`:
1415

1516
```toml
1617
[dependencies]
17-
18-
libc = "0.1"
18+
libc = "1.0"
1919
```
2020

21-
and this to your crate root:
21+
Next, add this to your crate root:
2222

2323
```rust
2424
extern crate libc;
2525
```
26+
27+
## What is libc?
28+
29+
The primary purpose of this crate is to provide all of the definitions necessary
30+
to easily interoperate with C code (or "C-like" code) on each of the platforms
31+
that Rust supports. This includes type definitions (e.g. `c_int`), constants
32+
(e.g. `EINVAL`) as well as function headers (e.g. `malloc`).
33+
34+
This crate does not strive to have any form of compatibility across platforms,
35+
but rather it is simply a straight binding to the system libraries on the
36+
platform in question.
37+
38+
## Public API
39+
40+
This crate exports all underlying platform types, functions, and constants under
41+
the crate root, so all items are accessible as `libc::foo`. The types and values
42+
of all the exported APIs match the platform that libc is compiled for.
43+
44+
More detailed information about the design of this library can be found in its
45+
[associated RFC][rfc].
46+
47+
[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1291-promote-libc.md
48+
49+
## Adding an API
50+
51+
Want to use an API which currently isn't bound in `libc`? It's quite easy to add
52+
one!
53+
54+
The internal structure of this crate is designed to minimize the number of
55+
`#[cfg]` attributes in order to easily be able to add new items which apply
56+
to all platforms in the future. As a result, the crate is organized
57+
hierarchically based on platform. Each module has a number of `#[cfg]`'d
58+
children, but only one is ever actually compiled. Each module then reexports all
59+
the contents of its children.
60+
61+
This means that for each platform that libc supports, the path from a
62+
leaf module to the root will contain all bindings for the platform in question.
63+
Consequently, this indicates where an API should be added! Adding an API at a
64+
particular level in the hierarchy means that it is supported on all the child
65+
platforms of that level. For example, when adding a Unix API it should be added
66+
to `src/unix/mod.rs`, but when adding a Linux-only API it should be added to
67+
`src/unix/notbsd/linux/mod.rs`.
68+
69+
If you're not 100% sure at what level of the hierarchy an API should be added
70+
at, fear not! This crate has CI support which tests any binding against all
71+
platforms supported, so you'll see failures if an API is added at the wrong
72+
level or has different signatures across platforms.
73+
74+
With that in mind, the steps for adding a new API are:
75+
76+
1. Determine where in the module hierarchy your API should be added.
77+
2. Add the API.
78+
3. Send a PR to this repo.
79+
4. Wait for CI to pass, fixing errors.
80+
5. Wait for a merge!
81+
82+
## Platforms and Documentation
83+
84+
The following platforms are currently tested and have documentation available:
85+
86+
Tested:
87+
* [`i686-pc-windows-msvc`](https://doc.rust-lang.org/libc/i686-pc-windows-msvc/libc)
88+
* [`x86_64-pc-windows-msvc`](https://doc.rust-lang.org/libc/x86_64-pc-windows-msvc/libc)
89+
(Windows)
90+
* [`i686-pc-windows-gnu`](https://doc.rust-lang.org/libc/i686-pc-windows-gnu/libc)
91+
* [`x86_64-pc-windows-gnu`](https://doc.rust-lang.org/libc/x86_64-pc-windows-gnu/libc)
92+
* [`i686-apple-darwin`](https://doc.rust-lang.org/libc/i686-apple-darwin/libc)
93+
* [`x86_64-apple-darwin`](https://doc.rust-lang.org/libc/x86_64-apple-darwin/libc)
94+
(OSX)
95+
* [`i686-apple-ios`](https://doc.rust-lang.org/libc/i686-apple-ios/libc)
96+
* [`x86_64-apple-ios`](https://doc.rust-lang.org/libc/x86_64-apple-ios/libc)
97+
(iOS)
98+
* [`i686-unknown-linux-gnu`](https://doc.rust-lang.org/libc/i686-unknown-linux-gnu/libc)
99+
* [`x86_64-unknown-linux-gnu`](https://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu/libc)
100+
(Linux)
101+
* [`x86_64-unknown-linux-musl`](https://doc.rust-lang.org/libc/x86_64-unknown-linux-musl/libc)
102+
(Linux MUSL)
103+
* [`aarch64-unknown-linux-gnu`](https://doc.rust-lang.org/libc/aarch64-unknown-linux-gnu/libc)
104+
* [`mips-unknown-linux-gnu`](https://doc.rust-lang.org/libc/mips-unknown-linux-gnu/libc)
105+
* [`arm-unknown-linux-gnueabihf`](https://doc.rust-lang.org/libc/arm-unknown-linux-gnueabihf/libc)
106+
* [`arm-linux-androideabi`](https://doc.rust-lang.org/libc/arm-linux-androideabi/libc)
107+
(Android)
108+
109+
The following may be supported, but are not guaranteed to always work:
110+
111+
* `x86_64-unknown-freebsd`
112+
* `i686-unknown-freebsd`
113+
* `x86_64-unknown-bitrig`
114+
* `x86_64-unknown-dragonfly`
115+
* `x86_64-unknown-openbsd`
116+
* `x86_64-unknown-netbsd`

appveyor.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
environment:
2+
matrix:
3+
- TARGET: x86_64-pc-windows-gnu
4+
MSYS2_BITS: 64
5+
- TARGET: i686-pc-windows-gnu
6+
MSYS2_BITS: 32
7+
- TARGET: x86_64-pc-windows-msvc
8+
- TARGET: i686-pc-windows-msvc
9+
install:
10+
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-nightly-${env:TARGET}.exe"
11+
- rust-nightly-%TARGET%.exe /VERYSILENT /NORESTART /DIR="C:\Program Files (x86)\Rust"
12+
- SET PATH=%PATH%;C:\Program Files (x86)\Rust\bin
13+
- if defined MSYS2_BITS set PATH=%PATH%;C:\msys64\mingw%MSYS2_BITS%\bin
14+
- rustc -V
15+
- cargo -V
16+
17+
build: false
18+
19+
test_script:
20+
- cargo test
21+
- cargo run --manifest-path libc-test/Cargo.toml
22+
23+
branches:
24+
only:
25+
- master

ci/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
The goal of the libc crate is to have CI running everywhere to have the
2+
strongest guarantees about the definitions that this library contains, and as a
3+
result the CI is pretty complicated and also pretty large! Hopefully this can
4+
serve as a guide through the sea of scripts in this directory and elsewhere in
5+
this project.
6+
7+
# Files
8+
9+
First up, let's talk about the files in this directory:
10+
11+
* `msys2.ps1` - a PowerShell script which is used to install MSYS2 on the
12+
AppVeyor bots. As of this writing MSYS2 isn't installed by default, and this
13+
script will install the right version/arch of msys2 in preparation of using
14+
the contained C compiler to compile C shims.
15+
16+
* `run-travis.sh` - a shell script run by all Travis builders, this is
17+
responsible for setting up the rest of the environment such as installing new
18+
packages, downloading Rust target libraries, etc.
19+
20+
* `run.sh` - the actual script which runs tests for a particular architecture.
21+
Called from the `run-travis.sh` script this will run all tests for the target
22+
specified.
23+
24+
* `cargo-config` - Cargo configuration of linkers to use copied into place by
25+
the `run-travis.sh` script before builds are run.
26+
27+
* `dox.sh` - script called from `run-travis.sh` on only the linux 64-bit nightly
28+
Travis bots to build documentation for this crate.
29+
30+
* `landing-page-*.html` - used by `dox.sh` to generate a landing page for all
31+
architectures' documentation.
32+
33+
# CI Systems
34+
35+
Currently this repository leverages a combination of Travis CI and AppVeyor for
36+
running tests. The triples tested are:
37+
38+
* AppVeyor
39+
* `{i686,x86_64}-pc-windows-{msvc,gnu}`
40+
* Travis
41+
* `{i686,x86_64,mips,aarch64}-unknown-linux-gnu`
42+
* `x86_64-unknown-linux-musl`
43+
* `arm-unknown-linux-gnueabihf`
44+
* `arm-linux-androideabi`
45+
* `{i686,x86_64}-apple-{darwin,ios}`
46+
47+
The Windows triples are all pretty standard, they just set up their environment
48+
then run tests, no need for downloading any extra target libs (we just download
49+
the right installer). The Intel Linux/OSX builds are similar in that we just
50+
download the right target libs and run tests. Note that the Intel Linux/OSX
51+
builds are run on stable/beta/nightly, but are the only ones that do so.
52+
53+
The remaining architectures look like:
54+
55+
* Android runs in a [docker image][android-docker] with an emulator, the NDK,
56+
and the SDK already set up. The entire build happens within the docker image.
57+
* The MIPS, ARM, and AArch64 builds all use QEMU to run the generated binary to
58+
actually verify the tests pass.
59+
* The MUSL build just has to download a MUSL compiler and target libraries and
60+
then otherwise runs tests normally.
61+
* iOS builds need an extra linker flag currently, but beyond that they're built
62+
as standard as everything else.
63+
64+
[android-docker]: https://github.com/rust-lang/rust-buildbot/blob/master/slaves/android/Dockerfile
65+
66+
Hopefully that's at least somewhat of an introduction to everything going on
67+
here, and feel free to ping @alexcrichton with questions!
68+

ci/Vagrantfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# A vagrant configuration file for running tests on BSD-like machines
2+
#
3+
# Note that this was originally intended to later be used to run tests on
4+
# Travis, but it didn't work out. Regardless this has stuck around! You can run
5+
# tests in FreeBSD via:
6+
#
7+
# git clone https://github.com/alexcrichton/libc
8+
# cd libc/ci
9+
# vagrant up freebsd
10+
# vagrant ssh freebsd
11+
# ...
12+
# cd /vagrant/libc-test
13+
# cargo run
14+
#
15+
# And "that's it"! You look up instructions on Vagrant's website for how to
16+
# install vagrant.
17+
18+
Vagrant.configure(2) do |config|
19+
# For a complete reference, please see the online documentation at
20+
# https://docs.vagrantup.com.
21+
22+
config.vm.synced_folder "..", "/vagrant"
23+
24+
config.vm.define :freebsd do |bsd|
25+
bsd.vm.box = "arkadi/freebsd-10.1-amd64"
26+
bsd.vm.provision :shell, inline: 'yes | sudo pkg install rust cargo'
27+
bsd.vm.provider "virtualbox" do |vb|
28+
vb.memory = "2048"
29+
end
30+
end
31+
32+
config.vm.define :openbsd do |bsd|
33+
bsd.vm.box = "bodgit/openbsd-5.7-amd64"
34+
bsd.vm.provider "virtualbox" do |vb|
35+
vb.memory = "2048"
36+
end
37+
end
38+
end

ci/cargo-config

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Configuration of which linkers to call on Travis for various architectures
2+
3+
[target.arm-linux-androideabi]
4+
linker = "arm-linux-androideabi-gcc"
5+
6+
[target.arm-unknown-linux-gnueabihf]
7+
linker = "arm-linux-gnueabihf-gcc-4.7"
8+
9+
[target.mips-unknown-linux-gnu]
10+
linker = "mips-linux-gnu-gcc"
11+
12+
[target.aarch64-unknown-linux-gnu]
13+
linker = "aarch64-linux-gnu-gcc"

ci/dox.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
# Builds documentation for all target triples that we have a registered URL for
4+
# in liblibc. This scrapes the list of triples to document from `src/lib.rs`
5+
# which has a bunch of `html_root_url` directives we pick up.
6+
7+
set -e
8+
9+
TARGETS=`grep html_root_url src/lib.rs | sed 's/.*".*\/\(.*\)"/\1/'`
10+
11+
rm -rf target/doc
12+
mkdir -p target/doc
13+
14+
cp ci/landing-page-head.html target/doc/index.html
15+
16+
for target in $TARGETS; do
17+
echo documenting $target
18+
19+
rustdoc -o target/doc/$target --target $target src/lib.rs --cfg dox \
20+
--crate-name libc
21+
22+
echo "<li><a href="$target/libc/index.html">$target</a></li>" \
23+
>> target/doc/index.html
24+
done
25+
26+
cat ci/landing-page-footer.html >> target/doc/index.html
27+
28+
# If we're on travis, not a PR, and on the right branch, publish!
29+
if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_BRANCH" = "master" ]; then
30+
pip install ghp-import --user $USER
31+
$HOME/.local/bin/ghp-import -n target/doc
32+
git push -qf https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
33+
fi

ci/landing-page-footer.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
</head>
6+
<body>
7+
<ul>

ci/landing-page-head.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
</ul>
2+
</body>
3+
</html>
4+

0 commit comments

Comments
 (0)