Add package
This commit is contained in:
parent
6c3aae7d27
commit
421921ef1c
16
.github/workflows/build.yaml
vendored
16
.github/workflows/build.yaml
vendored
|
@ -13,15 +13,15 @@ jobs:
|
||||||
|
|
||||||
- uses: DeterminateSystems/nix-installer-action-cache@main
|
- uses: DeterminateSystems/nix-installer-action-cache@main
|
||||||
|
|
||||||
- name: "Build something"
|
- name: Build package
|
||||||
run: "nix develop -c cargo build --release"
|
run: "nix build .# -L"
|
||||||
|
|
||||||
- name: Upload a Build Artifact
|
- name: Upload a Build Artifact
|
||||||
uses: actions/upload-artifact@v3.1.2
|
uses: actions/upload-artifact@v3.1.2
|
||||||
with:
|
with:
|
||||||
# Artifact name
|
# Artifact name
|
||||||
name: nix-actions-cache-macOS
|
name: nix-actions-cache-macOS
|
||||||
path: target/release/nix-actions-cache
|
path: result/bin/nix-actions-cache
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
check-artifacts-macOS:
|
check-artifacts-macOS:
|
||||||
|
@ -40,7 +40,7 @@ jobs:
|
||||||
cache-binary: ./cache-binary/nix-actions-cache
|
cache-binary: ./cache-binary/nix-actions-cache
|
||||||
|
|
||||||
- name: "Build something"
|
- name: "Build something"
|
||||||
run: "nix develop -c date"
|
run: "nix build .# -L"
|
||||||
|
|
||||||
build-artifacts-Linux:
|
build-artifacts-Linux:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
|
@ -49,15 +49,15 @@ jobs:
|
||||||
|
|
||||||
- uses: DeterminateSystems/nix-installer-action-cache@main
|
- uses: DeterminateSystems/nix-installer-action-cache@main
|
||||||
|
|
||||||
- name: "Build something"
|
- name: Build package
|
||||||
run: "nix develop -c cargo build --release --target x86_64-unknown-linux-musl"
|
run: "nix build .# -L"
|
||||||
|
|
||||||
- name: Upload a Build Artifact
|
- name: Upload a Build Artifact
|
||||||
uses: actions/upload-artifact@v3.1.2
|
uses: actions/upload-artifact@v3.1.2
|
||||||
with:
|
with:
|
||||||
# Artifact name
|
# Artifact name
|
||||||
name: nix-actions-cache-Linux
|
name: nix-actions-cache-Linux
|
||||||
path: target/x86_64-unknown-linux-musl/release/nix-actions-cache
|
path: result/bin/nix-actions-cache
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
check-artifacts-Linux:
|
check-artifacts-Linux:
|
||||||
|
@ -76,4 +76,4 @@ jobs:
|
||||||
cache-binary: ./cache-binary/nix-actions-cache
|
cache-binary: ./cache-binary/nix-actions-cache
|
||||||
|
|
||||||
- name: "Build something"
|
- name: "Build something"
|
||||||
run: "nix develop -c date"
|
run: "nix build .# -L"
|
||||||
|
|
89
crane.nix
Normal file
89
crane.nix
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
{ stdenv
|
||||||
|
, pkgs
|
||||||
|
, lib
|
||||||
|
, crane
|
||||||
|
, rustNightly
|
||||||
|
, rust
|
||||||
|
, nix-gitignore
|
||||||
|
, supportedSystems
|
||||||
|
}:
|
||||||
|
|
||||||
|
let
|
||||||
|
inherit (stdenv.hostPlatform) system;
|
||||||
|
|
||||||
|
# For easy cross-compilation in devShells
|
||||||
|
# We are just composing the pkgsCross.*.stdenv.cc together
|
||||||
|
crossPlatforms = let
|
||||||
|
makeCrossPlatform = crossSystem: let
|
||||||
|
pkgsCross =
|
||||||
|
if crossSystem == system then pkgs
|
||||||
|
else import pkgs.path {
|
||||||
|
inherit system crossSystem;
|
||||||
|
overlays = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
rustTargetSpec = rust.toRustTargetSpec pkgsCross.pkgsStatic.stdenv.hostPlatform;
|
||||||
|
rustTargetSpecUnderscored = builtins.replaceStrings [ "-" ] [ "_" ] rustTargetSpec;
|
||||||
|
|
||||||
|
cargoLinkerEnv = lib.strings.toUpper "CARGO_TARGET_${rustTargetSpecUnderscored}_LINKER";
|
||||||
|
cargoCcEnv = "CC_${rustTargetSpecUnderscored}"; # for ring
|
||||||
|
|
||||||
|
cc = "${pkgsCross.stdenv.cc}/bin/${pkgsCross.stdenv.cc.targetPrefix}cc";
|
||||||
|
in {
|
||||||
|
name = crossSystem;
|
||||||
|
value = {
|
||||||
|
inherit rustTargetSpec cc;
|
||||||
|
pkgs = pkgsCross;
|
||||||
|
env = {
|
||||||
|
"${cargoLinkerEnv}" = cc;
|
||||||
|
"${cargoCcEnv}" = cc;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
systems = lib.filter (s: s == system || lib.hasInfix "linux" s) supportedSystems;
|
||||||
|
in builtins.listToAttrs (map makeCrossPlatform systems);
|
||||||
|
|
||||||
|
cargoTargets = lib.mapAttrsToList (_: p: p.rustTargetSpec) crossPlatforms;
|
||||||
|
cargoCrossEnvs = lib.foldl (acc: p: acc // p.env) {} (builtins.attrValues crossPlatforms);
|
||||||
|
|
||||||
|
buildFor = system: let
|
||||||
|
crossPlatform = crossPlatforms.${system};
|
||||||
|
inherit (crossPlatform) pkgs;
|
||||||
|
craneLib = (crane.mkLib pkgs).overrideToolchain rustNightly;
|
||||||
|
|
||||||
|
pname = "nix-actions-cache";
|
||||||
|
|
||||||
|
src = nix-gitignore.gitignoreSource [] ./.;
|
||||||
|
|
||||||
|
buildInputs = with pkgs; []
|
||||||
|
++ lib.optionals pkgs.stdenv.isDarwin [
|
||||||
|
darwin.apple_sdk.frameworks.Security
|
||||||
|
];
|
||||||
|
|
||||||
|
# The Rust toolchain from rust-overlay has a dynamic libiconv in depsTargetTargetPropagated
|
||||||
|
# Our static libiconv needs to take precedence
|
||||||
|
nativeBuildInputs = with pkgs; []
|
||||||
|
++ lib.optionals pkgs.stdenv.isDarwin [
|
||||||
|
(libiconv.override { enableStatic = true; enableShared = false; })
|
||||||
|
];
|
||||||
|
|
||||||
|
cargoExtraArgs = "--target ${crossPlatform.rustTargetSpec}";
|
||||||
|
|
||||||
|
cargoArtifacts = craneLib.buildDepsOnly ({
|
||||||
|
inherit pname src buildInputs nativeBuildInputs cargoExtraArgs;
|
||||||
|
|
||||||
|
doCheck = false;
|
||||||
|
} // crossPlatform.env);
|
||||||
|
crate = craneLib.buildPackage ({
|
||||||
|
inherit pname src buildInputs nativeBuildInputs cargoExtraArgs;
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
|
||||||
|
# The resulting executable must be standalone
|
||||||
|
allowedRequisites = [];
|
||||||
|
} // crossPlatform.env);
|
||||||
|
in crate;
|
||||||
|
in {
|
||||||
|
inherit crossPlatforms cargoTargets cargoCrossEnvs;
|
||||||
|
|
||||||
|
nix-actions-cache = buildFor system;
|
||||||
|
}
|
50
flake.nix
50
flake.nix
|
@ -27,10 +27,6 @@
|
||||||
outputs = { self, nixpkgs, flake-utils, rust-overlay, crane, ... }: let
|
outputs = { self, nixpkgs, flake-utils, rust-overlay, crane, ... }: let
|
||||||
supportedSystems = flake-utils.lib.defaultSystems;
|
supportedSystems = flake-utils.lib.defaultSystems;
|
||||||
nightlyVersion = "2023-05-01";
|
nightlyVersion = "2023-05-01";
|
||||||
|
|
||||||
makeCranePkgs = pkgs: let
|
|
||||||
craneLib = crane.mkLib pkgs;
|
|
||||||
in pkgs.callPackage ./crane.nix { inherit craneLib; };
|
|
||||||
in flake-utils.lib.eachSystem supportedSystems (system: let
|
in flake-utils.lib.eachSystem supportedSystems (system: let
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
|
@ -41,40 +37,21 @@
|
||||||
|
|
||||||
inherit (pkgs) lib;
|
inherit (pkgs) lib;
|
||||||
|
|
||||||
crossPlatforms = let
|
|
||||||
makeCrossPlatform = crossSystem: let
|
|
||||||
pkgsCross = if crossSystem == system then pkgs else import nixpkgs {
|
|
||||||
inherit system crossSystem;
|
|
||||||
overlays = [];
|
|
||||||
};
|
|
||||||
rustTargetSpec = pkgs.rust.toRustTargetSpec pkgsCross.pkgsStatic.stdenv.hostPlatform;
|
|
||||||
rustTargetSpecUnderscored = builtins.replaceStrings [ "-" ] [ "_" ] rustTargetSpec;
|
|
||||||
in {
|
|
||||||
inherit rustTargetSpec;
|
|
||||||
cc = "${pkgsCross.stdenv.cc}/bin/${pkgsCross.stdenv.cc.targetPrefix}cc";
|
|
||||||
cargoLinkerEnv = lib.strings.toUpper "CARGO_TARGET_${rustTargetSpecUnderscored}_LINKER";
|
|
||||||
cargoCcEnv = "CC_${rustTargetSpecUnderscored}"; # for ring
|
|
||||||
};
|
|
||||||
systems = lib.filter (lib.hasInfix "linux") supportedSystems;
|
|
||||||
in map makeCrossPlatform systems;
|
|
||||||
|
|
||||||
rustNightly = pkgs.rust-bin.nightly.${nightlyVersion}.default.override {
|
rustNightly = pkgs.rust-bin.nightly.${nightlyVersion}.default.override {
|
||||||
extensions = [ "rust-src" "rust-analyzer-preview" ];
|
extensions = [ "rust-src" "rust-analyzer-preview" ];
|
||||||
targets = map (p: p.rustTargetSpec) crossPlatforms;
|
targets = cranePkgs.cargoTargets;
|
||||||
};
|
};
|
||||||
|
|
||||||
cargoCrossEnvs = lib.listToAttrs (lib.flatten (map (p: [
|
cranePkgs = pkgs.callPackage ./crane.nix {
|
||||||
{
|
inherit crane supportedSystems rustNightly;
|
||||||
name = p.cargoCcEnv;
|
};
|
||||||
value = p.cc;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = p.cargoLinkerEnv;
|
|
||||||
value = p.cc;
|
|
||||||
}
|
|
||||||
]) crossPlatforms));
|
|
||||||
in {
|
in {
|
||||||
|
packages = rec {
|
||||||
|
inherit (cranePkgs) nix-actions-cache;
|
||||||
|
default = nix-actions-cache;
|
||||||
|
};
|
||||||
devShells = {
|
devShells = {
|
||||||
|
inputsFrom = [ cranePkgs.nix-actions-cache ];
|
||||||
default = pkgs.mkShell ({
|
default = pkgs.mkShell ({
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
bashInteractive
|
bashInteractive
|
||||||
|
@ -83,11 +60,10 @@
|
||||||
cargo-bloat
|
cargo-bloat
|
||||||
cargo-edit
|
cargo-edit
|
||||||
cargo-udeps
|
cargo-udeps
|
||||||
]
|
|
||||||
++ lib.optional stdenv.hostPlatform.isDarwin darwin.apple_sdk.frameworks.Security
|
age
|
||||||
++ lib.optional stdenv.hostPlatform.isDarwin (libiconv.override { enableStatic = true; enableShared = false; })
|
];
|
||||||
;
|
} // cranePkgs.cargoCrossEnvs);
|
||||||
} // cargoCrossEnvs);
|
|
||||||
keygen = pkgs.mkShellNoCC {
|
keygen = pkgs.mkShellNoCC {
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
age
|
age
|
||||||
|
|
Loading…
Reference in a new issue