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:
pull_request:
push:
branches:
- main
- master
permissions:
contents: read
jobs:
check:
@ -29,6 +36,36 @@ jobs:
authToken: '${{ secrets.ATTIC_TOKEN }}'
- 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:
runs-on: ubuntu-latest
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": {
"naersk": {
"cross-naersk": {
"inputs": {
"naersk": [
"naersk"
],
"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": {
"lastModified": 1686242667,
"narHash": "sha256-I7Kwp06WX/9E+rEND1i1wjdKQQm3XiDxYOyNK9fuJu0=",
@ -23,31 +62,45 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1686059680,
"narHash": "sha256-sp0WlCIeVczzB0G8f8iyRg3IYW7KG31mI66z7HIZwrI=",
"lastModified": 1686331006,
"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",
"repo": "nixpkgs",
"rev": "a558f7ac29f50c4b937fb5c102f587678ae1c9fb",
"rev": "819fab520f664d72da4420a9705cf24932c684bb",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-23.05",
"ref": "release-23.05",
"type": "indirect"
}
},
"root": {
"inputs": {
"cross-naersk": "cross-naersk",
"flake-utils": "flake-utils",
"naersk": "naersk",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay",
"utils": "utils"
"nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"utils"
"flake-utils"
],
"nixpkgs": [
"nixpkgs"
@ -67,18 +120,18 @@
"type": "github"
}
},
"utils": {
"systems": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}

125
flake.nix
View file

@ -1,83 +1,106 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-23.05";
utils.url = "github:numtide/flake-utils";
nixpkgs.url = "nixpkgs/release-23.05";
flake-utils.url = "github:numtide/flake-utils";
naersk.url = "github:icewind1991/naersk?rev=6d245a3bbb2ee31ec726bb57b9a8b206302e7110";
naersk.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.url = "github:oxalica/rust-overlay";
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 = {
self,
nixpkgs,
utils,
flake-utils,
cross-naersk,
naersk,
nixpkgs,
rust-overlay,
...
}:
utils.lib.eachDefaultSystem (system: let
flake-utils.lib.eachDefaultSystem (system: let
overlays = [ (import rust-overlay) ];
pkgs = (import nixpkgs) {
inherit system overlays;
};
lib = pkgs.lib;
naerskForTarget = target: let
toolchain = pkgs.rust-bin.stable.latest.default.override { targets = [target]; };
in pkgs.callPackage naersk {
cargo = toolchain;
rustc = toolchain;
};
inherit (builtins) map replaceStrings;
inherit (lib.strings) hasInfix;
inherit (lib.attrsets) nameValuePair genAttrs listToAttrs;
hostTarget = pkgs.hostPlatform.config;
targets = ["x86_64-pc-windows-gnu" hostTarget];
hostNaersk = naerskForTarget hostTarget;
src = lib.sources.sourceByRegex (lib.cleanSource ./.) ["Cargo.*" "(src)(/.*)?"];
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
targets = [
"x86_64-unknown-linux-musl"
hostTarget
];
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 {
packages = (lib.attrsets.genAttrs targets (target: (naerskForTarget target).buildPackage (nearskOpt // {
CARGO_BUILD_TARGET = target;
} // (crossArgsFor target)))) // rec {
vbspview = packages.${hostTarget};
check = hostNaersk.buildPackage (nearskOpt // {
packages = serverPackages // clientPackages // rec {
shortcutd = packages.${hostTarget};
example-client = packages."${hostTarget}-example-client";
check = (cross-naersk' hostTarget).buildPackage (naerskOpt // {
mode = "check";
});
clippy = hostNaersk.buildPackage (nearskOpt // {
clippy = (cross-naersk' hostTarget).buildPackage (naerskOpt // {
mode = "clippy";
});
default = vbspview;
default = shortcutd;
};
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 {
nativeBuildInputs = with pkgs; [
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])}";
nativeBuildInputs = with pkgs; [rust-bin.stable.latest.default bacon cargo-edit cargo-outdated rustfmt clippy cargo-audit hyperfine valgrind];
};
});
}