This commit is contained in:
Robin Appelman 2023-06-17 20:10:21 +02:00
commit 60465ac735
4 changed files with 219 additions and 67 deletions

View file

@ -1,7 +1,14 @@
name: "CI" name: CI
on: on:
pull_request: pull_request:
push: push:
branches:
- main
- master
permissions:
contents: read
jobs: jobs:
check: check:
@ -29,6 +36,36 @@ jobs:
authToken: '${{ secrets.ATTIC_TOKEN }}' authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#clippy - run: nix build .#clippy
matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- id: set-matrix
run: echo "matrix=$(nix eval --json ".#matrix.x86_64-linux")" | tee $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: [check, matrix]
strategy:
fail-fast: false
matrix: ${{fromJson(needs.matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#${{ matrix.target }}
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.artifact_name }}-${{ matrix.target }}
path: result/bin/${{ matrix.artifact_name }}
test: test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: check needs: check

39
.github/workflows/release.yml vendored Normal file
View file

@ -0,0 +1,39 @@
name: Release
on:
release:
types: [created]
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- id: set-matrix
run: echo "matrix=$(nix eval --json ".#releaseMatrix.x86_64-linux")" | tee $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: matrix
strategy:
matrix: ${{fromJson(needs.matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#${{ matrix.target }}
- name: Upload binary to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: result/bin/${{ matrix.artifact_name }}
asset_name: ${{ matrix.asset_name }}
tag: ${{ github.ref }}

87
flake.lock generated
View file

@ -1,11 +1,50 @@
{ {
"nodes": { "nodes": {
"naersk": { "cross-naersk": {
"inputs": { "inputs": {
"naersk": [
"naersk"
],
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
] ]
}, },
"locked": {
"lastModified": 1686502198,
"narHash": "sha256-Ti8l6OOa/vpawiCJqiidE3vfsvVDfTQW4ls2PMSfoJE=",
"owner": "icewind1991",
"repo": "cross-naersk",
"rev": "2c2b9aae13700e4c3593aeef609dddb788fe5ae0",
"type": "github"
},
"original": {
"owner": "icewind1991",
"repo": "cross-naersk",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1685518550,
"narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"naersk": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": { "locked": {
"lastModified": 1686242667, "lastModified": 1686242667,
"narHash": "sha256-I7Kwp06WX/9E+rEND1i1wjdKQQm3XiDxYOyNK9fuJu0=", "narHash": "sha256-I7Kwp06WX/9E+rEND1i1wjdKQQm3XiDxYOyNK9fuJu0=",
@ -23,31 +62,45 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1686059680, "lastModified": 1686331006,
"narHash": "sha256-sp0WlCIeVczzB0G8f8iyRg3IYW7KG31mI66z7HIZwrI=", "narHash": "sha256-hElRDWUNG655aqF0awu+h5cmDN+I/dQcChRt2tGuGGU=",
"path": "/nix/store/wcgkp46gj4ca0700wprx42r51b60ws4l-source",
"rev": "85bcb95aa83be667e562e781e9d186c57a07d757",
"type": "path"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1687018574,
"narHash": "sha256-g3PubZfjWbHG4/tUt13NTlX+mgHbgAYWa5YJMyVJxjo=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "a558f7ac29f50c4b937fb5c102f587678ae1c9fb", "rev": "819fab520f664d72da4420a9705cf24932c684bb",
"type": "github" "type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "id": "nixpkgs",
"ref": "nixos-23.05", "ref": "release-23.05",
"type": "indirect" "type": "indirect"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"cross-naersk": "cross-naersk",
"flake-utils": "flake-utils",
"naersk": "naersk", "naersk": "naersk",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay", "rust-overlay": "rust-overlay"
"utils": "utils"
} }
}, },
"rust-overlay": { "rust-overlay": {
"inputs": { "inputs": {
"flake-utils": [ "flake-utils": [
"utils" "flake-utils"
], ],
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
@ -67,18 +120,18 @@
"type": "github" "type": "github"
} }
}, },
"utils": { "systems": {
"locked": { "locked": {
"lastModified": 1667395993, "lastModified": 1681028828,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "numtide", "owner": "nix-systems",
"repo": "flake-utils", "repo": "default",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "numtide", "owner": "nix-systems",
"repo": "flake-utils", "repo": "default",
"type": "github" "type": "github"
} }
} }

125
flake.nix
View file

@ -1,83 +1,106 @@
{ {
inputs = { inputs = {
nixpkgs.url = "nixpkgs/nixos-23.05"; nixpkgs.url = "nixpkgs/release-23.05";
utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
naersk.url = "github:icewind1991/naersk?rev=6d245a3bbb2ee31ec726bb57b9a8b206302e7110"; naersk.url = "github:icewind1991/naersk?rev=6d245a3bbb2ee31ec726bb57b9a8b206302e7110";
naersk.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.url = "github:oxalica/rust-overlay"; rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs"; rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.inputs.flake-utils.follows = "utils"; rust-overlay.inputs.flake-utils.follows = "flake-utils";
cross-naersk.url = "github:icewind1991/cross-naersk";
cross-naersk.inputs.nixpkgs.follows = "nixpkgs";
cross-naersk.inputs.naersk.follows = "naersk";
}; };
outputs = { outputs = {
self, self,
nixpkgs, flake-utils,
utils, cross-naersk,
naersk, naersk,
nixpkgs,
rust-overlay, rust-overlay,
...
}: }:
utils.lib.eachDefaultSystem (system: let flake-utils.lib.eachDefaultSystem (system: let
overlays = [ (import rust-overlay) ]; overlays = [ (import rust-overlay) ];
pkgs = (import nixpkgs) { pkgs = (import nixpkgs) {
inherit system overlays; inherit system overlays;
}; };
lib = pkgs.lib; lib = pkgs.lib;
naerskForTarget = target: let inherit (builtins) map replaceStrings;
toolchain = pkgs.rust-bin.stable.latest.default.override { targets = [target]; }; inherit (lib.strings) hasInfix;
in pkgs.callPackage naersk { inherit (lib.attrsets) nameValuePair genAttrs listToAttrs;
cargo = toolchain;
rustc = toolchain;
};
hostTarget = pkgs.hostPlatform.config; hostTarget = pkgs.hostPlatform.config;
targets = ["x86_64-pc-windows-gnu" hostTarget]; targets = [
hostNaersk = naerskForTarget hostTarget; "x86_64-unknown-linux-musl"
src = lib.sources.sourceByRegex (lib.cleanSource ./.) ["Cargo.*" "(src)(/.*)?"]; hostTarget
nearskOpt = {
pname = "vbspview";
root = src;
nativeBuildInputs = buildDependencies;
};
crossArgs = {
"x86_64-pc-windows-gnu" = {
nativeBuildInputs = [ pkgs.pkgsCross.mingwW64.stdenv.cc ];
overrideMain = args: args // { buildInputs = [ pkgs.pkgsCross.mingwW64.windows.pthreads ]; };
};
};
crossArgsFor = target: if (hostTarget != target) then (crossArgs.${target} or {}) else {};
buildDependencies = with pkgs; [
freetype
pkgconfig
dbus
libGL
]; ];
releaseTargets = lib.lists.remove hostTarget targets;
toolchain = (pkgs.rust-bin.stable.latest.default.override { inherit targets; });
assetNameForTarget = replaceStrings ["-unknown" "-gnu" "-musl" "eabihf" "-pc"] ["" "" "" "" ""];
cross-naersk' = pkgs.callPackage cross-naersk {inherit naersk;};
src = lib.sources.sourceByRegex (lib.cleanSource ./.) ["Cargo.*" "(server|client)(/.*)?"];
naerskOpt = {
pname = "shortcutd";
root = src;
};
buildMatrix = targets: {
include = (map (target: {
inherit target;
artifact_name = "shortcutd";
asset_name = "shortcutd-${assetNameForTarget target}";
}) targets ++ map (target: {
target = "${target}-example-client";
artifact_name = "client";
asset_name = "example-client-${assetNameForTarget target}";
}) targets);
};
serverPackages = genAttrs targets (target: (cross-naersk' target).buildPackage ({
pname = "shortcutd";
root = src;
}));
clientPackages = listToAttrs (map (target: nameValuePair "${target}-example-client" ((cross-naersk' target).buildPackage ({
pname = "shortcutd-example-client";
root = src;
overrideMain = x: {
preConfigure = ''
cargo_build_options="$cargo_build_options --example client"
'';
};
}))) targets);
in rec { in rec {
packages = (lib.attrsets.genAttrs targets (target: (naerskForTarget target).buildPackage (nearskOpt // { packages = serverPackages // clientPackages // rec {
CARGO_BUILD_TARGET = target; shortcutd = packages.${hostTarget};
} // (crossArgsFor target)))) // rec { example-client = packages."${hostTarget}-example-client";
vbspview = packages.${hostTarget}; check = (cross-naersk' hostTarget).buildPackage (naerskOpt // {
check = hostNaersk.buildPackage (nearskOpt // {
mode = "check"; mode = "check";
}); });
clippy = hostNaersk.buildPackage (nearskOpt // { clippy = (cross-naersk' hostTarget).buildPackage (naerskOpt // {
mode = "clippy"; mode = "clippy";
}); });
default = vbspview; default = shortcutd;
}; };
inherit targets; inherit targets;
inherit releaseTargets;
matrix = buildMatrix targets;
releaseMatrix = buildMatrix releaseTargets;
apps = rec {
tf-demo-parser = flake-utils.lib.mkApp {
drv = packages.tf-demo-parser;
exePath = "/bin/parse_demo";
};
default = tf-demo-parser;
};
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [rust-bin.stable.latest.default bacon cargo-edit cargo-outdated rustfmt clippy cargo-audit hyperfine valgrind];
pkgs.rust-bin.stable.latest.default
bacon
cargo-edit
cargo-outdated
clippy
cargo-audit
cargo-msrv
] ++ buildDependencies;
LD_LIBRARY_PATH = with pkgs; "/run/opengl-driver/lib/:${lib.makeLibraryPath ([libGL libGLU])}";
}; };
}); });
} }