diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 00000000..22d09a5a --- /dev/null +++ b/.clippy.toml @@ -0,0 +1 @@ +msrv = "1.32" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..9e8ea5b2 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,286 @@ +name: Tests + +on: + push: + branches: 0.1 + pull_request: + branches: 0.1 + schedule: + - cron: "0 12 * * 1" + +env: + CARGO_INCREMENTAL: 0 + RUSTFLAGS: "-Dwarnings" + +jobs: + check-doc: + name: Docs, deadlinks, minimal dependencies + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly # Needed for -Z minimal-versions + override: true + - name: Install precompiled cargo-deadlinks + run: | + export URL=$(curl -s https://api.github.com/repos/deadlinks/cargo-deadlinks/releases/latest | jq -r '.assets[] | select(.name | contains("cargo-deadlinks-linux")) | .browser_download_url') + wget -O /tmp/cargo-deadlinks $URL + chmod +x /tmp/cargo-deadlinks + mv /tmp/cargo-deadlinks ~/.cargo/bin + - run: cargo deadlinks -- --features=log,std + - run: | + cargo generate-lockfile -Z minimal-versions + cargo test --features=log,std + + main-tests: + name: Main tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + toolchain: [nightly, beta, stable, 1.34] + # Only Test macOS on stable to reduce macOS CI jobs + include: + - os: macos-latest + toolchain: stable + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.toolchain }} + override: true + - run: cargo test + - run: cargo test --features=std + - run: cargo test --features=log + - if: ${{ matrix.toolchain == 'nightly' }} + run: cargo build --benches + + linux-tests: + name: Additional Linux targets + runs-on: ubuntu-latest + strategy: + matrix: + target: [ + x86_64-unknown-linux-musl, + i686-unknown-linux-gnu, + i686-unknown-linux-musl, + ] + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + target: ${{ matrix.target }} + toolchain: stable + - name: Install multilib + # update is needed to fix the 404 error on install, see: + # https://github.com/actions/virtual-environments/issues/675 + run: | + sudo apt-get update + sudo apt-get install gcc-multilib + - run: cargo test --target=${{ matrix.target }} --features=std + + # We can only Build/Link on these targets for now. + # TODO: Run the iOS binaries in the simulator + # TODO: build/run aarch64-apple-darwin binaries on a x86_64 Mac + apple-tests: + name: Additional Apple targets + runs-on: macos-latest + strategy: + matrix: + target: [ + aarch64-apple-ios, + x86_64-apple-ios, + ] + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + target: ${{ matrix.target }} + toolchain: stable + - name: Build Tests + run: cargo test --no-run --target=${{ matrix.target }} --features=std + + windows-tests: + name: Additional Windows targets + runs-on: windows-latest + strategy: + matrix: + toolchain: [ + stable-x86_64-gnu, + stable-i686-gnu, + stable-i686-msvc, + ] + steps: + - uses: actions/checkout@v2 + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.toolchain }} + override: true + - run: cargo test --features=std + + # TODO: Add emscripten when it's working with Cross + cross-tests: + name: Cross Test + runs-on: ubuntu-latest + strategy: + matrix: + target: [ + aarch64-unknown-linux-gnu, + aarch64-linux-android, + mips-unknown-linux-gnu, + ] + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + target: ${{ matrix.target }} + toolchain: stable + - name: Install precompiled cross + run: | + export URL=$(curl -s https://api.github.com/repos/rust-embedded/cross/releases/latest | jq -r '.assets[] | select(.name | contains("x86_64-unknown-linux-gnu.tar.gz")) | .browser_download_url') + wget -O /tmp/binaries.tar.gz $URL + tar -C /tmp -xzf /tmp/binaries.tar.gz + mv /tmp/cross ~/.cargo/bin + - name: Test + run: cross test --no-fail-fast --target=${{ matrix.target }} --features=std + + cross-link: + name: Cross Build/Link + runs-on: ubuntu-latest + strategy: + matrix: + target: [ + x86_64-sun-solaris, + x86_64-unknown-netbsd, + ] + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + target: ${{ matrix.target }} + toolchain: stable + - name: Install precompiled cross + run: | + export URL=$(curl -s https://api.github.com/repos/rust-embedded/cross/releases/latest | jq -r '.assets[] | select(.name | contains("x86_64-unknown-linux-gnu.tar.gz")) | .browser_download_url') + wget -O /tmp/binaries.tar.gz $URL + tar -C /tmp -xzf /tmp/binaries.tar.gz + mv /tmp/cross ~/.cargo/bin + - name: Build Tests + run: cross test --no-run --target=${{ matrix.target }} --features=std + + web-tests: + name: Web tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + target: wasm32-unknown-unknown + toolchain: stable + - name: Install precompiled wasm-bindgen-test-runner + run: | + export VERSION=$(cargo metadata --format-version=1 | jq -r '.packages[] | select ( .name == "wasm-bindgen" ) | .version') + wget -O /tmp/binaries.tar.gz https://github.com/rustwasm/wasm-bindgen/releases/download/$VERSION/wasm-bindgen-$VERSION-x86_64-unknown-linux-musl.tar.gz + tar -C /tmp -xzf /tmp/binaries.tar.gz --strip-components=1 + mv /tmp/wasm-bindgen-test-runner ~/.cargo/bin + - name: Test (Node) + run: cargo test --target=wasm32-unknown-unknown --features=wasm-bindgen + - name: Test (Firefox) + env: + GECKODRIVER: /usr/bin/geckodriver + run: cargo test --target=wasm32-unknown-unknown --features=test-in-browser + - name: Test (Chrome) + env: + CHROMEDRIVER: /usr/bin/chromedriver + run: cargo test --target=wasm32-unknown-unknown --features=test-in-browser + - name: Build Tests (with dummy, without JS) + run: cargo test --no-run --target=wasm32-unknown-unknown --features=dummy + + wasi-tests: + name: WASI test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + target: wasm32-wasi + toolchain: stable + - name: Install precompiled wasmtime + run: | + export URL=$(curl -s https://api.github.com/repos/bytecodealliance/wasmtime/releases/latest | jq -r '.assets[] | select(.name | contains("x86_64-linux.tar.xz")) | .browser_download_url') + wget -O /tmp/binaries.tar.xz $URL + tar -C /tmp -xf /tmp/binaries.tar.xz --strip-components=1 + mv /tmp/wasmtime ~/.cargo/bin + - run: cargo test --target wasm32-wasi + + build: + name: Build only + runs-on: ubuntu-latest + strategy: + matrix: + target: [ + x86_64-unknown-freebsd, + x86_64-fuchsia, + x86_64-unknown-redox, + x86_64-fortanix-unknown-sgx, + ] + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + target: ${{ matrix.target }} + toolchain: nightly # Required to build libc for Redox + override: true + - name: Build + run: cargo build --target=${{ matrix.target }} --features=std + + build-std: + name: Build-only (build-std) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly # Required to build libcore + components: rust-src + override: true + - name: UEFI (RDRAND) + run: cargo build -Z build-std=core --target=x86_64-unknown-uefi + - name: Hermit (RDRAND) + run: cargo build -Z build-std=core --target=x86_64-unknown-hermit + - name: L4Re (RDRAND) + run: cargo build -Z build-std=core --target=x86_64-unknown-l4re-uclibc + - name: VxWorks + run: cargo build -Z build-std=core --target=x86_64-wrs-vxworks + + clippy-fmt: + name: Clippy + rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + # https://github.com/rust-lang/rust-clippy/pull/6379 added MSRV + # support, so we need to use nightly until this is on stable. + toolchain: nightly + components: rustfmt, clippy + override: true + - name: clippy + run: cargo clippy --all --features=std + - name: fmt + run: cargo fmt --all -- --check diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index bac7be27..00000000 --- a/.travis.yml +++ /dev/null @@ -1,234 +0,0 @@ -language: rust -sudo: false -dist: focal - -matrix: - include: - - name: "Linux, 1.32.0" - rust: 1.32.0 - os: linux - - - name: "OSX, 1.32.0" - rust: 1.32.0 - os: osx - - - name: "Linux, stable" - rust: stable - - - name: "OSX+iOS, stable" - rust: stable - os: osx - install: - - rustup target add aarch64-apple-ios - script: - - cargo test - - cargo test --examples - - cargo build --target aarch64-apple-ios - - - name: "Linux, beta" - rust: beta - - - name: "WASM via stdweb, wasm-bindgen and WASI" - rust: stable - addons: - # firefox: latest - chrome: stable - install: - - rustup target add wasm32-unknown-unknown - - rustup target add wasm32-wasi - # Get latest geckodriver - # - export VERSION=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest | jq -r ".tag_name") - # - wget -O geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/$VERSION/geckodriver-$VERSION-linux64.tar.gz - # - tar -xzf geckodriver.tar.gz - # Get latest chromedirver - - export VERSION=$(wget -q -O - https://chromedriver.storage.googleapis.com/LATEST_RELEASE) - - wget -O chromedriver.zip https://chromedriver.storage.googleapis.com/$VERSION/chromedriver_linux64.zip - - unzip chromedriver.zip - # Get cargo-web - # - export VERSION=0.6.26 # Pin version for stability - # - wget -O cargo-web.gz https://github.com/koute/cargo-web/releases/download/$VERSION/cargo-web-x86_64-unknown-linux-gnu.gz - # - gunzip cargo-web.gz - # - chmod +x cargo-web - # Get wasmtime - - export VERSION=v0.19.0 # Pin version for stability - - wget -O wasmtime.tar.xz https://github.com/CraneStation/wasmtime/releases/download/$VERSION/wasmtime-$VERSION-x86_64-linux.tar.xz - - tar -xf wasmtime.tar.xz --strip-components=1 - # Get wasm-bindgen-test-runner which matches our wasm-bindgen version - - export VERSION=$(cargo metadata --format-version=1 | jq -r '.packages[] | select ( .name == "wasm-bindgen" ) | .version') - - wget -O wasm-bindgen.tar.gz https://github.com/rustwasm/wasm-bindgen/releases/download/$VERSION/wasm-bindgen-$VERSION-x86_64-unknown-linux-musl.tar.gz - - tar -xzf wasm-bindgen.tar.gz --strip-components=1 - # Place the runner binaries in our PATH - - mv wasmtime wasm-bindgen-test-runner $HOME/.cargo/bin - script: - # wasi tests - - cargo test --target wasm32-wasi - # stdweb tests (Node, Chrome) - # stdweb (wasm32-unknown-unknown) tests are currently broken (see https://github.com/koute/cargo-web/issues/243) - # - cargo web test --nodejs --target=wasm32-unknown-unknown --features=stdweb - # - cargo web test --target=wasm32-unknown-unknown --features=stdweb - # wasm-bindgen tests (Node, Firefox, Chrome) - - cargo test --target wasm32-unknown-unknown --features=wasm-bindgen - # Firefox is broken, see https://github.com/rustwasm/wasm-bindgen/issues/2261 - # - GECKODRIVER=$PWD/geckodriver cargo test --target wasm32-unknown-unknown --features=test-in-browser - - CHROMEDRIVER=$PWD/chromedriver cargo test --target wasm32-unknown-unknown --features=test-in-browser - - - name: "WASM via Emscripten" - rust: stable - env: - - CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_RUNNER=node - - CARGO_TARGET_ASMJS_UNKNOWN_EMSCRIPTEN_RUNNER=node - install: - - rustup target add wasm32-unknown-emscripten - - rustup target add asmjs-unknown-emscripten - - export VERSION=2.0.2 # Pin version for stability - - git clone https://github.com/emscripten-core/emsdk.git - - ./emsdk/emsdk install $VERSION - - ./emsdk/emsdk activate $VERSION - - source ./emsdk/emsdk_env.sh - script: - - cargo test --target wasm32-unknown-emscripten - # Prevent 'wasm2js does not support source maps yet' error. - - RUSTFLAGS='-C debuginfo=0' cargo test --target asmjs-unknown-emscripten - - - name: "Linux, nightly, docs" - rust: nightly - os: linux - install: - - cargo --list | egrep "^\s*deadlinks$" -q || cargo install cargo-deadlinks - - cargo deadlinks -V - script: - - cargo test - - cargo test --benches - - cargo test --examples - # remove cached documentation, otherwise files from previous PRs can get included - - rm -rf target/doc - - cargo doc --no-deps --all --features=std,log - - cargo deadlinks --dir target/doc - # also test minimum dependency versions are usable - - cargo generate-lockfile -Z minimal-versions - - cargo test - - - name: "OSX, nightly, docs" - rust: nightly - os: osx - install: - - cargo --list | egrep "^\s*deadlinks$" -q || cargo install cargo-deadlinks - - cargo deadlinks -V - script: - - cargo test - - cargo test --benches - - cargo test --examples - # remove cached documentation, otherwise files from previous PRs can get included - - rm -rf target/doc - - cargo doc --no-deps --all --features=std,log - - cargo deadlinks --dir target/doc - # also test minimum dependency versions are usable - - cargo generate-lockfile -Z minimal-versions - - cargo test - - - name: "cross-platform build only" - rust: nightly - install: - - rustup target add x86_64-sun-solaris - - rustup target add x86_64-unknown-freebsd - - rustup target add x86_64-fuchsia - - rustup target add x86_64-unknown-netbsd - - rustup target add x86_64-unknown-redox - - rustup target add x86_64-fortanix-unknown-sgx - # For no_std targets - - rustup component add rust-src - - cargo install cargo-xbuild || true - script: - - cargo build --target=x86_64-sun-solaris - - cargo build --target=x86_64-unknown-freebsd - - cargo build --target=x86_64-fuchsia - - cargo build --target=x86_64-unknown-netbsd - - cargo build --target=x86_64-unknown-redox - - cargo build --target=x86_64-fortanix-unknown-sgx - # This builds currently fails with: - # Could not find specification for target "x86_64-unknown-cloudabi" - #- cargo xbuild --target=x86_64-unknown-cloudabi - - cargo xbuild --target=x86_64-unknown-uefi - - cargo xbuild --target=x86_64-unknown-hermit - - cargo xbuild --target=x86_64-unknown-l4re-uclibc - - cargo xbuild --target=x86_64-wrs-vxworks - # also test minimum dependency versions are usable - - cargo generate-lockfile -Z minimal-versions - - cargo build --target=x86_64-sun-solaris - - cargo build --target=x86_64-unknown-freebsd - - cargo build --target=x86_64-fuchsia - - cargo build --target=x86_64-unknown-netbsd - - cargo build --target=x86_64-unknown-redox - - cargo build --target=x86_64-fortanix-unknown-sgx - #- cargo xbuild --target=x86_64-unknown-cloudabi - - cargo xbuild --target=x86_64-unknown-uefi - - cargo xbuild --target=x86_64-unknown-hermit - - cargo xbuild --target=x86_64-unknown-l4re-uclibc - - cargo xbuild --target=x86_64-uwp-windows-gnu - - # Trust cross-built/emulated targets. We must repeat all non-default values. - - name: "Linux (MIPS, big-endian)" - env: TARGET=mips-unknown-linux-gnu - rust: stable - sudo: required - dist: trusty - services: docker - install: - - sh utils/ci/install.sh - - source ~/.cargo/env || true - script: - - bash utils/ci/script.sh - - - name: "Android (ARMv7)" - env: TARGET=armv7-linux-androideabi - rust: stable - sudo: required - dist: trusty - services: docker - install: - - sh utils/ci/install.sh - - source ~/.cargo/env || true - script: - - bash utils/ci/script.sh - - - name: "rustfmt" - rust: stable - install: - - rustup component add rustfmt - script: - - cargo fmt --all -- */*.rs --check - - allow_failures: - # Formatting errors should appear in Travis, but not break the build. - - name: "rustfmt" - -before_install: - - set -e - - rustup self update - -before_script: - - export RUSTFLAGS="-D warnings" - -script: - - cargo test - - cargo test --examples - -after_script: set +e - -cache: - cargo: true - directories: - - .local/share/cargo-web - -before_cache: - # Travis can't cache files that are not readable by "others" - - chmod -R a+r $HOME/.cargo - -notifications: - email: - on_success: never - -branches: - only: - - master - - 0.1 diff --git a/README.md b/README.md index 01bbfb5e..9d78ed72 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,18 @@ # getrandom -[![Build Status](https://travis-ci.org/rust-random/getrandom.svg?branch=master)](https://travis-ci.org/rust-random/getrandom) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-random/getrandom?svg=true)](https://ci.appveyor.com/project/rust-random/getrandom) -[![Crate](https://img.shields.io/crates/v/getrandom.svg)](https://crates.io/crates/getrandom) -[![Documentation](https://docs.rs/getrandom/badge.svg)](https://docs.rs/getrandom) -[![Dependency status](https://deps.rs/repo/github/rust-random/getrandom/status.svg)](https://deps.rs/repo/github/rust-random/getrandom) +[![Build Status]][GitHub Actions] [![Crate]][crates.io] [![Documentation]][docs.rs] [![Dependency Status]][deps.rs] [![Downloads]][crates.io] [![License]][LICENSE-MIT] + +[GitHub Actions]: https://github.com/rust-random/getrandom/actions?query=workflow:Tests+branch:0.1 +[Build Status]: https://github.com/rust-random/getrandom/workflows/Tests/badge.svg?branch=0.1 +[crates.io]: https://crates.io/crates/getrandom/0.1.16 +[Crate]: https://img.shields.io/badge/crates.io-v0.1.16-orange.svg +[docs.rs]: https://docs.rs/getrandom/0.1 +[Documentation]: https://docs.rs/getrandom/badge.svg?version=0.1 +[deps.rs]: https://deps.rs/crate/getrandom/0.1.16 +[Dependency Status]: https://deps.rs/crate/getrandom/0.1.16/status.svg +[Downloads]: https://img.shields.io/crates/d/getrandom +[LICENSE-MIT]: https://raw.githubusercontent.com/rust-random/getrandom/0.1/LICENSE-MIT +[License]: https://img.shields.io/crates/l/getrandom A Rust library for retrieving random data from (operating) system source. It is diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index c176544b..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,53 +0,0 @@ -environment: - - # At the time this was added AppVeyor was having troubles with checking - # revocation of SSL certificates of sites like static.rust-lang.org and what - # we think is crates.io. The libcurl HTTP client by default checks for - # revocation on Windows and according to a mailing list [1] this can be - # disabled. - # - # The `CARGO_HTTP_CHECK_REVOKE` env var here tells cargo to disable SSL - # revocation checking on Windows in libcurl. Note, though, that rustup, which - # we're using to download Rust here, also uses libcurl as the default backend. - # Unlike Cargo, however, rustup doesn't have a mechanism to disable revocation - # checking. To get rustup working we set `RUSTUP_USE_HYPER` which forces it to - # use the Hyper instead of libcurl backend. Both Hyper and libcurl use - # schannel on Windows but it appears that Hyper configures it slightly - # differently such that revocation checking isn't turned on by default. - # - # [1]: https://curl.haxx.se/mail/lib-2016-03/0202.html - RUSTUP_USE_HYPER: 1 - CARGO_HTTP_CHECK_REVOKE: false - - matrix: - - TARGET: x86_64-pc-windows-msvc - CHANNEL: 1.32.0 - - TARGET: x86_64-pc-windows-msvc - CHANNEL: stable - - TARGET: x86_64-pc-windows-msvc - CHANNEL: nightly - - TARGET: i686-pc-windows-msvc - CHANNEL: nightly - - TARGET: x86_64-pc-windows-gnu - CHANNEL: nightly - - TARGET: i686-pc-windows-gnu - CHANNEL: nightly - -install: - - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe - - rustup-init.exe -y --default-host %TARGET% --default-toolchain %CHANNEL% - - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin - - rustc -V - - cargo -V - -build: false - -test_script: - - set RUSTFLAGS=-D warnings - - cargo test - - cargo test --examples - -branches: - only: - - master - - 0.1 \ No newline at end of file