diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 892af1e..919c97b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,41 +1,57 @@ name: CI on: [push, pull_request] +env: + CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse + jobs: test: name: Test runs-on: ${{ matrix.os }} strategy: matrix: - rust: ["1.63", stable, beta, nightly] - os: [ubuntu-latest, macos-latest, windows-latest] + rust: [stable, beta, nightly] + os: [ubuntu-latest, macos-14, windows-latest] steps: - uses: actions/checkout@master - name: Install Rust (rustup) - run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }} + run: | + rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal + rustup default ${{ matrix.rust }} shell: bash - - run: cargo test + - uses: Swatinem/rust-cache@v2 + + - run: cargo test --locked + + - name: Cache make compiled + if: ${{ !startsWith(matrix.os, 'windows') }} + id: cache-make + uses: actions/cache@v4 + with: + path: /usr/local/bin/make + key: ${{ runner.os }}-make-4.4.1 # Compile it from source (temporarily) - name: Make GNU Make from source - if: ${{ !startsWith(matrix.os, 'windows') }} + if: ${{ !startsWith(matrix.os, 'windows') && steps.cache-make.outputs.cache-hit != 'true' }} env: VERSION: "4.4.1" shell: bash run: | - wget -q "https://ftp.gnu.org/gnu/make/make-${VERSION}.tar.gz" - tar zxf "make-${VERSION}.tar.gz" + curl "https://ftp.gnu.org/gnu/make/make-${VERSION}.tar.gz" | tar xz pushd "make-${VERSION}" ./configure - make + make -j 4 popd - cp -rp "make-${VERSION}/make" . + cp -p "make-${VERSION}/make" /usr/local/bin + - name: Test against GNU Make from source if: ${{ !startsWith(matrix.os, 'windows') }} shell: bash - run: - MAKE="${PWD}/make" cargo test + run: cargo test --locked + env: + MAKE: /usr/local/bin/make rustfmt: name: Rustfmt @@ -63,3 +79,19 @@ jobs: git -c user.name='ci' -c user.email='ci' commit -m init git push -f -q https://git:${{ secrets.github_token }}@github.com/${{ github.repository }} HEAD:gh-pages if: github.event_name == 'push' && github.event.ref == 'refs/heads/master' + + msrv: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-14, windows-latest] + steps: + - uses: actions/checkout@master + - name: Install Rust (rustup) + run: rustup toolchain install nightly --no-self-update --profile minimal + shell: bash + + - uses: taiki-e/install-action@cargo-hack + - uses: Swatinem/rust-cache@v2 + + - run: cargo hack check --lib --rust-version --ignore-private --locked diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..7531774 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,142 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + +[[package]] +name = "jobserver" +version = "0.1.28" +dependencies = [ + "libc", + "tempfile", +] + +[[package]] +name = "libc" +version = "0.2.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" + +[[package]] +name = "linux-raw-sys" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" + +[[package]] +name = "rustix" +version = "0.38.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" diff --git a/Cargo.toml b/Cargo.toml index 9e94b53..42e72ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,14 +13,10 @@ edition = "2021" rust-version = "1.63" [target.'cfg(unix)'.dependencies] -libc = "0.2.50" +libc = "0.2.72" [dev-dependencies] -futures = "0.1" -num_cpus = "1.0" -tempfile = "3" -tokio-core = "0.1" -tokio-process = "0.2" +tempfile = "3.10.1" [[test]] name = "client" diff --git a/tests/client.rs b/tests/client.rs index 2516b8c..f10a10c 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -7,11 +7,7 @@ use std::sync::mpsc; use std::sync::Arc; use std::thread; -use futures::future::{self, Future}; -use futures::stream::{self, Stream}; use jobserver::Client; -use tokio_core::reactor::Core; -use tokio_process::CommandExt; macro_rules! t { ($e:expr) => { @@ -24,9 +20,9 @@ macro_rules! t { struct Test { name: &'static str, - f: &'static dyn Fn(), + f: &'static (dyn Fn() + Send + Sync), make_args: &'static [&'static str], - rule: &'static dyn Fn(&str) -> String, + rule: &'static (dyn Fn(&str) -> String + Send + Sync), } const TESTS: &[Test] = &[ @@ -118,9 +114,7 @@ fn main() { let me = me.to_str().unwrap(); let filter = env::args().nth(1); - let mut core = t!(Core::new()); - - let futures = TESTS + let join_handles = TESTS .iter() .filter(|test| match filter { Some(ref s) => test.name.contains(s), @@ -138,33 +132,33 @@ all: (test.rule)(me) ); t!(t!(File::create(td.path().join("Makefile"))).write_all(makefile.as_bytes())); - let prog = env::var("MAKE").unwrap_or_else(|_| "make".to_string()); - let mut cmd = Command::new(prog); - cmd.args(test.make_args); - cmd.current_dir(td.path()); - future::lazy(move || { - cmd.output_async().map(move |e| { - drop(td); - (test, e) - }) + thread::spawn(move || { + let prog = env::var("MAKE").unwrap_or_else(|_| "make".to_string()); + let mut cmd = Command::new(prog); + cmd.args(test.make_args); + cmd.current_dir(td.path()); + + (test, cmd.output().unwrap()) }) }) .collect::>(); - println!("\nrunning {} tests\n", futures.len()); + println!("\nrunning {} tests\n", join_handles.len()); - let stream = stream::iter(futures.into_iter().map(Ok)).buffer_unordered(num_cpus::get()); + let failures = join_handles + .into_iter() + .filter_map(|join_handle| { + let (test, output) = join_handle.join().unwrap(); - let mut failures = Vec::new(); - t!(core.run(stream.for_each(|(test, output)| { - if output.status.success() { - println!("test {} ... ok", test.name); - } else { - println!("test {} ... FAIL", test.name); - failures.push((test, output)); - } - Ok(()) - }))); + if output.status.success() { + println!("test {} ... ok", test.name); + None + } else { + println!("test {} ... FAIL", test.name); + Some((test, output)) + } + }) + .collect::>(); if failures.is_empty() { println!("\ntest result: ok\n");