From 1941355128adc17440f0a8d297b7abf3655219f5 Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Sun, 16 Jul 2023 13:29:44 +0530 Subject: [PATCH] Imrove builds - Add more build targets - Allow cross compile (if you have the resources, I don't) - Fix failing nixos tests --- .github/workflows/cd.yml | 101 ++++++++++++---------- .github/workflows/ci.yml | 176 +++++++++++++++++++++------------------ .gitignore | 3 + docs/en/src/sum-type.md | 2 +- flake.lock | 89 +------------------- flake.nix | 38 +++++---- src/path.rs | 15 ++-- 7 files changed, 187 insertions(+), 237 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index ca26841..79461ca 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -12,71 +12,86 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: - - macos-latest - - ubuntu-latest - - ubuntu-20.04 + build: + - macos + - macos-aarch64 + - linux + - linux-musl + - aarch64-linux + # - aarch64-linux-musl + - aarch64-android + # - armv7-linux rust: [stable] include: # See the list: https://github.com/cross-rs/cross - - os: macos-latest - artifact_prefix: macos + - build: macos + os: macos-latest target: x86_64-apple-darwin binary_postfix: "" - - os: ubuntu-latest - artifact_prefix: linux + - build: macos-aarch64 + os: macos-latest + target: aarch64-apple-darwin + binary_postfix: "" + + - build: linux + os: ubuntu-latest target: x86_64-unknown-linux-gnu binary_postfix: "" - - os: ubuntu-20.04 - artifact_prefix: linux-musl + - build: linux-musl + os: ubuntu-latest target: x86_64-unknown-linux-musl binary_postfix: "" - # Will see later + - build: aarch64-linux + os: ubuntu-latest + target: aarch64-unknown-linux-gnu + binary_postfix: "" + + # - build: aarch64-linux-musl + # os: ubuntu-latest + # target: aarch64-unknown-linux-musl + # binary_postfix: "" + + - build: aarch64-android + os: ubuntu-latest + target: aarch64-linux-android + binary_postfix: "" - # - os: ubuntu-latest - # artifact_prefix: x86_64-android - # target: x86_64-linux-android - # binary_postfix: '' - # - # - os: ubuntu-latest - # artifact_prefix: aarch64-android - # target: aarch64-linux-android - # binary_postfix: '' + # - build: armv7-linux + # os: ubuntu-latest + # target: armv7-unknown-linux-gnueabihf + # binary_postfix: "" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Installing Rust toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ matrix.rust }} target: ${{ matrix.target }} - override: true - name: Installing needed macOS dependencies if: matrix.os == 'macos-latest' run: brew install openssl@1.1 - name: Installing needed Ubuntu dependencies - if: matrix.os == 'ubuntu-latest' || matrix.os == 'ubuntu-20.04' + if: matrix.os == 'ubuntu-latest' run: | sudo apt-get update --fix-missing - sudo apt-get install -y -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev + sudo apt-get install -y --no-install-recommends liblua5.1-0-dev libluajit-5.1-dev + + - if: matrix.os == 'ubuntu-latest' && contains(matrix.build, 'armv7') + run: sudo apt-get install -y --no-install-recommends gcc-arm-linux-gnueabihf libc-dev-armhf-cross - - name: Checking out sources - uses: actions/checkout@v1 + - if: matrix.os == 'ubuntu-latest' && contains(matrix.build, 'aarch64') + run: sudo apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu libc6-dev-arm64-cross - name: Running cargo build - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: build - toolchain: ${{ matrix.rust }} - args: --locked --release --target ${{ matrix.target }} + run: cargo build --locked --release --target ${{ matrix.target }} - name: Install gpg secret key run: | @@ -89,7 +104,7 @@ jobs: cd target/${{ matrix.target }}/release BINARY_NAME=xplr${{ matrix.binary_postfix }} strip $BINARY_NAME - RELEASE_NAME=xplr-${{ matrix.artifact_prefix }} + RELEASE_NAME=xplr-${{ matrix.build }} tar czvf $RELEASE_NAME.tar.gz $BINARY_NAME shasum -a 256 $RELEASE_NAME.tar.gz > $RELEASE_NAME.sha256 cat <(echo "${{ secrets.GPG_PASS }}") | gpg --pinentry-mode loopback --passphrase-fd 0 --detach-sign --armor $RELEASE_NAME.tar.gz @@ -98,9 +113,9 @@ jobs: uses: softprops/action-gh-release@v1 with: files: | - target/${{ matrix.target }}/release/xplr-${{ matrix.artifact_prefix }}.tar.gz - target/${{ matrix.target }}/release/xplr-${{ matrix.artifact_prefix }}.sha256 - target/${{ matrix.target }}/release/xplr-${{ matrix.artifact_prefix }}.tar.gz.asc + target/${{ matrix.target }}/release/xplr-${{ matrix.build }}.tar.gz + target/${{ matrix.target }}/release/xplr-${{ matrix.build }}.sha256 + target/${{ matrix.target }}/release/xplr-${{ matrix.build }}.tar.gz.asc env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -108,7 +123,7 @@ jobs: name: Publishing GPG signature runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install gpg secret key run: | cat <(echo -e "${{ secrets.GPG_SECRET }}") | gpg --batch --import @@ -133,20 +148,16 @@ jobs: name: Publishing to Cargo runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 + - uses: dtolnay/rust-toolchain@stable with: toolchain: stable - override: true - run: | sudo apt-get update --fix-missing sudo apt-get install -y -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev - - uses: actions-rs/cargo@v1 - with: - command: publish - args: --allow-dirty + - run: cargo publish --allow-dirty env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_API_KEY }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ebe8ed..3062e6a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,130 +11,144 @@ jobs: name: Check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable with: toolchain: stable - profile: minimal - override: true - - uses: actions-rs/cargo@v1 + - run: cargo check + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable with: - command: check + toolchain: stable + components: rustfmt + - run: cargo fmt --all -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + components: clippy + - run: cargo clippy -- -D warnings + + spellcheck: + name: Spellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: codespell-project/actions-codespell@v1 + with: + ignore_words_file: .codespellignore test: name: Test Suite runs-on: ${{ matrix.os }} + needs: + - check + - fmt + - clippy + - spellcheck strategy: matrix: - os: - - macos-latest - - ubuntu-latest - - ubuntu-20.04 + build: + - macos + - macos-aarch64 + - linux + - linux-musl + - aarch64-linux + # - aarch64-linux-musl + - aarch64-android + # - armv7-linux rust: [stable] include: - - os: macos-latest - artifact_prefix: macos + # See the list: https://github.com/cross-rs/cross + + - build: macos + os: macos-latest target: x86_64-apple-darwin binary_postfix: "" - - os: ubuntu-latest - artifact_prefix: linux + + - build: macos-aarch64 + os: macos-latest + target: aarch64-apple-darwin + binary_postfix: "" + + - build: linux + os: ubuntu-latest target: x86_64-unknown-linux-gnu binary_postfix: "" - - os: ubuntu-20.04 - artifact_prefix: linux-musl + + - build: linux-musl + os: ubuntu-latest target: x86_64-unknown-linux-musl binary_postfix: "" + - build: aarch64-linux + os: ubuntu-latest + target: aarch64-unknown-linux-gnu + binary_postfix: "" + + # - build: aarch64-linux-musl + # os: ubuntu-latest + # target: aarch64-unknown-linux-musl + # binary_postfix: "" + + - build: aarch64-android + os: ubuntu-latest + target: aarch64-linux-android + binary_postfix: "" + + # - build: armv7-linux + # os: ubuntu-latest + # target: armv7-unknown-linux-gnueabihf + # binary_postfix: "" + env: RUST_BACKTRACE: full steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Installing Rust toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ matrix.rust }} target: ${{ matrix.target }} - override: true - name: Installing needed macOS dependencies if: matrix.os == 'macos-latest' run: brew install openssl@1.1 - name: Installing needed Ubuntu dependencies - if: matrix.os == 'ubuntu-latest' || matrix.os == 'ubuntu-20.04' + if: matrix.os == 'ubuntu-latest' run: | sudo apt-get update --fix-missing - sudo apt-get install -y -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev + sudo apt-get install -y --no-install-recommends liblua5.1-0-dev libluajit-5.1-dev - - name: Build - uses: actions-rs/cargo@v1 - with: - command: build - toolchain: ${{ matrix.rust }} - args: --target ${{ matrix.target }} + - if: matrix.os == 'ubuntu-latest' && contains(matrix.build, 'armv7') + run: sudo apt-get install -y --no-install-recommends gcc-arm-linux-gnueabihf libc-dev-armhf-cross - - name: Test - uses: actions-rs/cargo@v1 - with: - command: test - toolchain: ${{ matrix.rust }} - args: --target ${{ matrix.target }} + - if: matrix.os == 'ubuntu-latest' && contains(matrix.build, 'aarch64') + run: sudo apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu libc6-dev-arm64-cross + - run: cargo build --target ${{ matrix.target }} + - run: cargo test --target ${{ matrix.target }} # bench: # name: Benchmarks # runs-on: ubuntu-latest # steps: - # - uses: actions/checkout@v2 - # - uses: actions-rs/toolchain@v1 + # - uses: actions/checkout@v3 + # - uses: dtolnay/rust-toolchain@stable # with: # toolchain: stable - # profile: minimal - # override: true # # These dependencies are required for `clipboard` # - run: sudo apt-get install -y -qq libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev - # - uses: actions-rs/cargo@v1 - # with: - # command: bench - - fmt: - name: Rustfmt - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true - components: rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - clippy: - name: Clippy - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true - components: clippy - - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings - - spellcheck: - name: Spellcheck - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: codespell-project/actions-codespell@v1 - with: - ignore_words_file: .codespellignore + # - run: cargo bench diff --git a/.gitignore b/.gitignore index 863591b..555f146 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ book/ # direnv .direnv/ + +# nix +result diff --git a/docs/en/src/sum-type.md b/docs/en/src/sum-type.md index 777aa65..cf7f654 100644 --- a/docs/en/src/sum-type.md +++ b/docs/en/src/sum-type.md @@ -89,7 +89,7 @@ have nested types in each branch. --- If you're still confused about something, or if you found an error in this -explaination, feel free to [discuss together][5]. +explanation, feel free to [discuss together][5]. [1]: https://en.wikipedia.org/wiki/Tagged_union [2]: layout.md diff --git a/flake.lock b/flake.lock index 10d2cb9..a06872f 100644 --- a/flake.lock +++ b/flake.lock @@ -1,91 +1,6 @@ { "nodes": { - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "lowdown-src": { - "flake": false, - "locked": { - "lastModified": 1633514407, - "narHash": "sha256-Dw32tiMjdK9t3ETl5fzGrutQTzh2rufgZV4A/BbxuD4=", - "owner": "kristapsdz", - "repo": "lowdown", - "rev": "d2c2b44ff6c27b936ec27358a2653caaef8f73b8", - "type": "github" - }, - "original": { - "owner": "kristapsdz", - "repo": "lowdown", - "type": "github" - } - }, - "nix": { - "inputs": { - "lowdown-src": "lowdown-src", - "nixpkgs": "nixpkgs", - "nixpkgs-regression": "nixpkgs-regression" - }, - "locked": { - "lastModified": 1676545802, - "narHash": "sha256-EK4rZ+Hd5hsvXnzSzk2ikhStJnD63odF7SzsQ8CuSPU=", - "owner": "domenkozar", - "repo": "nix", - "rev": "7c91803598ffbcfe4a55c44ac6d49b2cf07a527f", - "type": "github" - }, - "original": { - "owner": "domenkozar", - "ref": "relaxed-flakes", - "repo": "nix", - "type": "github" - } - }, "nixpkgs": { - "locked": { - "lastModified": 1657693803, - "narHash": "sha256-G++2CJ9u0E7NNTAi9n5G8TdDmGJXcIjkJ3NF8cetQB8=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "365e1b3a859281cf11b94f87231adeabbdd878a2", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-22.05-small", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-regression": { - "locked": { - "lastModified": 1643052045, - "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", - "type": "github" - }, - "original": { - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", - "type": "github" - } - }, - "nixpkgs_2": { "locked": { "lastModified": 1689422397, "narHash": "sha256-fnopownlSBGTBYxGdTdUPM215yG/UEEj3wgheBLIbHs=", @@ -102,9 +17,7 @@ }, "root": { "inputs": { - "flake-compat": "flake-compat", - "nix": "nix", - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index 41ab521..b3220d1 100644 --- a/flake.nix +++ b/flake.nix @@ -3,31 +3,26 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs"; - nix.url = "github:domenkozar/nix/relaxed-flakes"; - flake-compat = { - url = "github:edolstra/flake-compat"; - flake = false; - }; }; - outputs = { self, nixpkgs, nix, ... }: + outputs = inputs@{ self, nixpkgs, ... }: let - systems = [ - "x86_64-linux" - "i686-linux" - "x86_64-darwin" - "aarch64-linux" - "aarch64-linux-android" - "aarch64-darwin" - ]; - forAllSystems = f: builtins.listToAttrs (map (name: { inherit name; value = f name; }) systems); + lib = nixpkgs.lib; + + darwin = [ "x86_64-darwin" "aarch64-darwin" ]; + linux = [ "x86_64-linux" "x86_64-linux-musl" "aarch64-linux" "aarch64-linux-android" "i86_64-linux" ]; + allSystems = darwin ++ linux; + + forEachSystem = systems: f: lib.genAttrs systems (system: f system); + forAllSystems = forEachSystem allSystems; in { packages = forAllSystems (system: let pkgs = import nixpkgs { inherit system; }; in - { + rec { + # e.g. nix build .#xplr xplr = pkgs.rustPlatform.buildRustPackage rec { name = "xplr"; src = ./.; @@ -35,6 +30,14 @@ lockFile = ./Cargo.lock; }; }; + + # e.g. nix build .#cross.x86_64-linux-musl.xplr --impure + cross = forEachSystem (lib.filter (sys: sys != system) allSystems) (targetSystem: + let + crossPkgs = import nixpkgs { localSystem = system; crossSystem = targetSystem; }; + in + { inherit (crossPkgs) xplr; } + ); } ); defaultPackage = forAllSystems (system: self.packages.${system}.xplr); @@ -55,6 +58,9 @@ default = pkgs.mkShell { RUST_BACKTRACE = 1; + # For cross compilation + NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM = 1; + buildInputs = devRequirements; packages = devRequirements; }; diff --git a/src/path.rs b/src/path.rs index 1f18725..73e2c52 100644 --- a/src/path.rs +++ b/src/path.rs @@ -216,17 +216,20 @@ mod tests { #[test] fn test_relative_to_parent() { - let path = std::env::current_dir().unwrap(); + let path = std::env::current_dir().unwrap().join("docs"); let parent = path.parent().unwrap(); - let relative = relative_to(parent, NONE).unwrap(); + let base = default().with_base(path.to_str().unwrap()); + + let relative = relative_to(parent, Some(&base)).unwrap(); assert_eq!(relative, PathBuf::from("..")); - let relative = relative_to(parent, Some(&default().with_prefix_dots())).unwrap(); + let relative = + relative_to(parent, Some(&base.clone().with_prefix_dots())).unwrap(); assert_eq!(relative, PathBuf::from("..")); let relative = - relative_to(parent, Some(&default().without_suffix_dots())).unwrap(); + relative_to(parent, Some(&base.clone().without_suffix_dots())).unwrap(); assert_eq!( relative, PathBuf::from("../..").join(parent.file_name().unwrap()) @@ -234,12 +237,12 @@ mod tests { let relative = relative_to( parent, - Some(&default().with_prefix_dots().without_suffix_dots()), + Some(&base.clone().with_prefix_dots().without_suffix_dots()), ) .unwrap(); assert_eq!( relative, - PathBuf::from("../..").join(parent.file_name().unwrap()) + PathBuf::from("../..").join(parent.clone().file_name().unwrap()) ); }