Skip to content

Commit

Permalink
ci: build current binaries with crane
Browse files Browse the repository at this point in the history
  • Loading branch information
CertainLach committed Mar 25, 2024
1 parent c2313a2 commit a6dd70c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 65 deletions.
21 changes: 21 additions & 0 deletions flake.lock

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

50 changes: 19 additions & 31 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs = {
nixpkgs,
flake-utils,
rust-overlay,
crane,
...
}:
flake-utils.lib.eachDefaultSystem (
Expand All @@ -22,16 +29,8 @@
overlays = [rust-overlay.overlays.default];
config.allowUnsupportedSystem = true;
};
lib = pkgs.lib;
rust =
(pkgs.rustChannelOf {
date = "2024-01-10";
channel = "nightly";
})
.default
.override {
extensions = ["rust-src" "miri" "rust-analyzer" "clippy"];
};
rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rust;
in {
packages = rec {
default = jrsonnet;
Expand All @@ -40,19 +39,19 @@
jsonnet = pkgs.callPackage ./nix/jsonnet.nix {};
# I didn't managed to build it, and nixpkgs version is marked as broken
# haskell-jsonnet = pkgs.callPackage ./nix/haskell-jsonnet.nix { };

jrsonnet = pkgs.callPackage ./nix/jrsonnet.nix {
rustPlatform = pkgs.makeRustPlatform {
rustc = rust;
cargo = rust;
};
inherit craneLib;
};
jrsonnet-nightly = pkgs.callPackage ./nix/jrsonnet.nix {
rustPlatform = pkgs.makeRustPlatform {
rustc = rust;
cargo = rust;
};
inherit craneLib;
withNightlyFeatures = true;
};
jrsonnet-experimental = pkgs.callPackage ./nix/jrsonnet.nix {
inherit craneLib;
withExperimentalFeatures = true;
};

jrsonnet-release = pkgs.callPackage ./nix/jrsonnet-release.nix {
rustPlatform = pkgs.makeRustPlatform {
rustc = rust;
Expand Down Expand Up @@ -115,20 +114,9 @@
];
};
};
packagesCross = lib.genAttrs ["mingwW64"] (crossSystem: let
callPackage = pkgs.pkgsCross.${crossSystem}.callPackage;
in {
jrsonnet = callPackage ./nix/jrsonnet.nix {
# rustPlatform = pkgs.makeRustPlatform {
# rustc = rust;
# cargo = rust;
# };
};
});
devShells.default = pkgs.mkShell {
devShells.default = craneLib.devShell {
nativeBuildInputs = with pkgs; [
alejandra
rust
cargo-edit
cargo-asm
cargo-outdated
Expand Down
15 changes: 8 additions & 7 deletions nix/jrsonnet-release.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{ lib, fetchFromGitHub, rustPlatform, runCommand, makeWrapper }:


{
fetchFromGitHub,
rustPlatform,
makeWrapper,
}:
rustPlatform.buildRustPackage rec {
pname = "jrsonnet";
version = "pre9";
Expand All @@ -13,11 +15,10 @@ rustPlatform.buildRustPackage rec {
};
cargoHash = "sha256-y2YiktT1h263vpFaC+kRL8yaAWQThhEkS+NSQ6B6Ylk=";

cargoTestFlags = ["--package=jrsonnet --features=mimalloc,legacy-this-file"];
cargoBuildFlags = ["--package=jrsonnet --features=mimalloc,legacy-this-file"];

cargoTestFlags = [ "--package=jrsonnet --features=mimalloc,legacy-this-file" ];
cargoBuildFlags = [ "--package=jrsonnet --features=mimalloc,legacy-this-file" ];

buildInputs = [ makeWrapper ];
buildInputs = [makeWrapper];

postInstall = ''
wrapProgram $out/bin/jrsonnet --add-flags "--max-stack=200000 --os-stack=200000"
Expand Down
37 changes: 12 additions & 25 deletions nix/jrsonnet.nix
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
{
lib,
rustPlatform,
runCommand,
craneLib,
makeWrapper,
withNightlyFeatures ? false,
withExperimentalFeatures ? false,
forBenchmarks ? false,
}:
with lib; let
filteredSrc = builtins.path {
name = "jrsonnet-src-filtered";
filter = path: type: !(builtins.baseNameOf path == "flake.nix" || builtins.baseNameOf path == "nix");
path = ../.;
};

# for some reason, filteredSrc hash still depends on nix directory contents
# Moving it into a CA store drops leftover references
src =
runCommand "jrsonnet-src"
{
__contentAddressed = true;
} "cp -r '${filteredSrc}' $out";
in
rustPlatform.buildRustPackage rec {
inherit src;
with lib;
craneLib.buildPackage rec {
src = lib.cleanSourceWith {
src = ../.;
filter = path: type:
(lib.hasSuffix "\.jsonnet" path)
|| (craneLib.filterCargoSources path type);
};
pname = "jrsonnet";
version = "current${optionalString withNightlyFeatures "-nightly"}";
version = "current${optionalString withNightlyFeatures "-nightly"}${optionalString withExperimentalFeatures "-experimental"}";

cargoTestFlags = [
"--features=mimalloc,legacy-this-file${optionalString withNightlyFeatures ",nightly"}"
"--features=mimalloc,legacy-this-file${optionalString withNightlyFeatures ",nightly"}${optionalString withExperimentalFeatures ",experimental"}"
];
cargoBuildFlags = cargoTestFlags;

Expand All @@ -37,8 +28,4 @@ in
postInstall = optionalString forBenchmarks ''
wrapProgram $out/bin/jrsonnet --add-flags "--max-stack=200000 --os-stack=200000"
'';

cargoLock = {
lockFile = ../Cargo.lock;
};
}
4 changes: 2 additions & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-10-28"
components = ["rustfmt", "clippy"]
channel = "nightly-2024-01-10"
components = ["rustfmt", "clippy", "rust-analyzer", "rust-src"]

0 comments on commit a6dd70c

Please sign in to comment.