diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9221a7..188de41 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,11 @@ on: branches: [main] pull_request: workflow_dispatch: + +env: + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} + CARGO_INCREMENTAL: 0 + jobs: ci: name: ${{ matrix.os }} @@ -24,10 +29,20 @@ jobs: components: rustfmt, clippy profile: minimal override: true - - uses: cachix/install-nix-action@v15 + - uses: cachix/install-nix-action@v16 if: ${{ matrix.os != 'windows-latest' }} with: - nix_path: nixpkgs=channel:nixpkgs-unstable + nix_path: nixpkgs=channel:nixos-unstable + - uses: cachix/cachix-action@v10 + if: ${{ matrix.os != 'windows-latest' && env.CACHIX_AUTH_TOKEN != '' }} + with: + authToken: ${{ env.CACHIX_AUTH_TOKEN }} + name: zoxide + + - name: Setup cache + uses: Swatinem/rust-cache@v1 + if: + ${{ matrix.os == 'windows-latest' }} - run: cargo xtask ci if: ${{ matrix.os == 'windows-latest' }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e5fc83b..9a4ae52 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,6 +6,9 @@ on: pull_request: workflow_dispatch: +env: + CARGO_INCREMENTAL: 0 + jobs: release: name: ${{ matrix.target }} @@ -58,6 +61,9 @@ jobs: override: true target: ${{ matrix.target }} + - name: Setup cache + uses: Swatinem/rust-cache@v1 + - name: Build binary uses: actions-rs/cargo@v1 with: diff --git a/Cargo.toml b/Cargo.toml index 8779684..4ed0ca7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,10 @@ ordered-float = "2.0.0" serde = { version = "1.0.116", features = ["derive"] } [target.'cfg(unix)'.dependencies] -nix = { version = "0.24.1", default-features = false, features = ["fs", "user"] } +nix = { version = "0.24.1", default-features = false, features = [ + "fs", + "user", +] } [build-dependencies] clap = { version = "3.1.0", features = ["derive"] } @@ -46,7 +49,11 @@ tempfile = "3.1.0" default = [] nix-dev = [] +[profile.dev] +debug = 0 + [profile.release] codegen-units = 1 +debug = 0 lto = true strip = true diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 0000000..4e38b0f --- /dev/null +++ b/Cross.toml @@ -0,0 +1,2 @@ +[build.env] +passthrough = ["CARGO_INCREMENTAL"] diff --git a/shell.nix b/shell.nix index 01ee619..7a1be1d 100644 --- a/shell.nix +++ b/shell.nix @@ -38,5 +38,6 @@ in pkgs.mkShell { pkgs.libiconv ]; - RUST_BACKTRACE = 1; + CARGO_INCREMENTAL = builtins.getEnv "CI" != ""; + CARGO_TARGET_DIR = "target_nix"; } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 4af61c6..f9d7573 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -54,8 +54,13 @@ impl CommandExt for &mut Command { } fn run_ci(nix_enabled: bool) -> Result<()> { + // Run cargo-clippy. let color: &[&str] = if is_ci() { &["--color=always"] } else { &[] }; - Command::new("cargo").args(&["check", "--all-features"]).args(color)._run()?; + Command::new("cargo") + .args(&["clippy", "--all-features", "--all-targets"]) + .args(color) + .args(&["--", "-Dwarnings"]) + ._run()?; run_fmt(nix_enabled, true)?; run_lint(nix_enabled)?; @@ -84,14 +89,6 @@ fn run_fmt(nix_enabled: bool, check: bool) -> Result<()> { } fn run_lint(nix_enabled: bool) -> Result<()> { - // Run cargo-clippy. - let color: &[&str] = if is_ci() { &["--color=always"] } else { &[] }; - Command::new("cargo") - .args(&["clippy", "--all-features", "--all-targets"]) - .args(color) - .args(&["--", "-Dwarnings"]) - ._run()?; - if nix_enabled { // Run cargo-audit. let color: &[&str] = if is_ci() { &["--color=always"] } else { &[] }; @@ -136,7 +133,6 @@ fn enable_nix() -> bool { } let nix_enabled = env::var_os("IN_NIX_SHELL").unwrap_or_default() == "pure"; if nix_enabled { - env::set_var("CARGO_TARGET_DIR", "target_nix"); return true; } let nix_detected = Command::new("nix-shell").arg("--version").status().map(|s| s.success()).unwrap_or(false);