Skip to content

Commit

Permalink
feat: add binary artifacts and static builds (#31)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com>
  • Loading branch information
getchoo and ryanccn authored Mar 29, 2024
1 parent e3ebf16 commit 0adae88
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 116 deletions.
58 changes: 53 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@ on:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_call:
workflow_dispatch:

jobs:
build:
strategy:
matrix:
runner:
- ubuntu-latest
- macos-latest
- windows-latest
target:
- aarch64-apple-darwin
- x86_64-apple-darwin
- x86_64-pc-windows-msvc
include:
- target: aarch64-apple-darwin
runner: macos-14
- target: x86_64-apple-darwin
runner: macos-latest
- target: x86_64-pc-windows-msvc
runner: windows-latest

runs-on: ${{ matrix.runner }}

Expand All @@ -25,9 +34,48 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
target: ${{ matrix.target }}

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2

- name: Build
run: cargo build --release --locked
run: cargo build --release --locked --target ${{ matrix.target }}

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
if-no-files-found: "error"
name: nrr-${{ matrix.target }}
path: |
./target/${{ matrix.target }}/release/nrr
./target/${{ matrix.target }}/release/nrr.exe
linux-static:
strategy:
matrix:
arch:
- x86_64
- aarch64

runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v10

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v4

- name: Build
run: nix build --fallback --print-build-logs '.#nrr-static-${{ matrix.arch }}'

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
if-no-files-found: "error"
name: nrr-${{ matrix.arch }}-unknown-linux-musl
path: ./result/bin/nrr
56 changes: 55 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ on:
tags: ["v*.*.*"]

jobs:
publish:
build:
uses: ./.github/workflows/build.yml

crates-io:
name: Publish to crates.io
needs: build

runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -24,3 +33,48 @@ jobs:
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_API_TOKEN }}

github:
name: Make GitHub release
needs: build

runs-on: ubuntu-latest

permissions:
contents: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download artifacts
id: download
uses: actions/download-artifact@v4
with:
path: /tmp/artifacts

- name: Prepare assets
env:
ARTIFACTS: ${{ steps.download.outputs.download-path }}
id: prepare
run: |
asset_path="/tmp/assets"
mkdir -p "$asset_path"
for artifact in "$ARTIFACTS"/*/; do
basename "$artifact" | \
xargs -I {} zip -jr "$asset_path"/{}.zip "$artifact"
done
echo "asset-path=$asset_path" >> "$GITHUB_OUTPUT"
- name: Create release
env:
ASSETS: ${{ steps.prepare.outputs.asset-path }}
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
gh release create \
--draft \
--notes-from-tag \
--verify-tag \
"$TAG" \
"$ASSETS"/*.zip
63 changes: 0 additions & 63 deletions default.nix

This file was deleted.

66 changes: 62 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 39 additions & 39 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,43 @@

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";

rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
};

outputs = {
self,
nixpkgs,
flake-utils,
...
}: let
version = builtins.substring 0 8 self.lastModifiedDate or "dirty";

inherit (nixpkgs) lib;

systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
} @ inputs:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
config = {};
overlays = [
inputs.rust-overlay.overlays.default
self.overlays.default
];
};

forAllSystems = fn: lib.genAttrs systems (s: fn nixpkgs.legacyPackages.${s});
in {
checks = forAllSystems (pkgs: let
formatter = self.formatter.${pkgs.system};
in {
fmt =
pkgs.runCommand "check-fmt" {}
''
${pkgs.lib.getExe formatter} --check ${self}
inherit (pkgs) lib;
in rec {
checks = {
fmt = pkgs.runCommand "check-fmt" {} ''
${lib.getExe formatter} --check ${./.}
touch $out
'';
});
};

devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
devShells.default = pkgs.mkShell {
packages = with pkgs; [
rust-analyzer
rustc
Expand All @@ -51,25 +55,21 @@
RUST_BACKTRACE = 1;
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
});

packages = forAllSystems (
pkgs: let
scope = lib.makeScope pkgs.newScope;
fn = final: {p = self.overlays.default final pkgs;};
inherit (scope fn) p;
in
p // {default = p.nrr;}
);
packages = {
inherit (pkgs) nrr;
default = pkgs.nrr;
};

formatter = forAllSystems (p: p.alejandra);
legacyPackages = let
staticPkgs = import ./nix/static.nix pkgs;
in (lib.optionalAttrs pkgs.stdenv.isLinux staticPkgs);

overlays.default = _: prev: {
nrr = prev.callPackage ./default.nix {
inherit self version;
inherit (prev.darwin.apple_sdk_11_0.frameworks) CoreFoundation Security;
inherit (prev.darwin) IOKit;
formatter = pkgs.alejandra;
})
// {
overlays.default = _: prev: {
nrr = prev.callPackage ./nix/package.nix {};
};
};
};
}
Loading

0 comments on commit 0adae88

Please sign in to comment.