2022-01-17 02:30:07 +03:00
|
|
|
{
|
|
|
|
description = "Build a cargo project with a custom toolchain";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
|
|
|
|
2024-08-30 02:29:16 +03:00
|
|
|
crane.url = "github:ipetkov/crane";
|
2022-01-17 02:30:07 +03:00
|
|
|
|
2022-04-28 04:10:22 +03:00
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
2022-01-17 02:30:07 +03:00
|
|
|
|
2022-04-28 04:10:22 +03:00
|
|
|
rust-overlay = {
|
|
|
|
url = "github:oxalica/rust-overlay";
|
2024-07-14 19:36:42 +03:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
2022-04-28 04:10:22 +03:00
|
|
|
};
|
2022-01-17 02:30:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, ... }:
|
|
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
|
|
let
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
overlays = [ (import rust-overlay) ];
|
|
|
|
};
|
|
|
|
|
|
|
|
# NB: we don't need to overlay our custom toolchain for the *entire*
|
|
|
|
# pkgs (which would require rebuidling anything else which uses rust).
|
|
|
|
# Instead, we just want to update the scope that crane will use by appending
|
|
|
|
# our specific toolchain there.
|
2024-06-29 21:29:52 +03:00
|
|
|
craneLib = (crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.stable.latest.default.override {
|
|
|
|
targets = [ "wasm32-wasi" ];
|
|
|
|
});
|
2022-01-17 02:30:07 +03:00
|
|
|
|
|
|
|
my-crate = craneLib.buildPackage {
|
2024-06-11 06:53:46 +03:00
|
|
|
src = craneLib.cleanCargoSource ./.;
|
2023-10-16 01:25:34 +03:00
|
|
|
strictDeps = true;
|
2022-01-17 02:30:07 +03:00
|
|
|
|
|
|
|
cargoExtraArgs = "--target wasm32-wasi";
|
|
|
|
|
|
|
|
# Tests currently need to be run via `cargo wasi` which
|
|
|
|
# isn't packaged in nixpkgs yet...
|
|
|
|
doCheck = false;
|
2022-11-20 03:08:15 +03:00
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
# Add additional build inputs here
|
|
|
|
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
|
|
|
|
# Additional darwin specific inputs can be set here
|
|
|
|
pkgs.libiconv
|
|
|
|
];
|
2022-01-17 02:30:07 +03:00
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
checks = {
|
|
|
|
inherit my-crate;
|
|
|
|
};
|
|
|
|
|
2022-04-28 05:23:30 +03:00
|
|
|
packages.default = my-crate;
|
2022-01-17 02:30:07 +03:00
|
|
|
|
2022-04-28 05:23:30 +03:00
|
|
|
apps.default = flake-utils.lib.mkApp {
|
2022-01-17 02:30:07 +03:00
|
|
|
drv = pkgs.writeShellScriptBin "my-app" ''
|
|
|
|
${pkgs.wasmtime}/bin/wasmtime run ${my-crate}/bin/custom-toolchain.wasm
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-09-03 20:33:10 +03:00
|
|
|
devShells.default = craneLib.devShell {
|
|
|
|
# Inherit inputs from checks.
|
|
|
|
checks = self.checks.${system};
|
2022-01-17 02:30:07 +03:00
|
|
|
|
2023-09-03 20:33:10 +03:00
|
|
|
# Extra inputs can be added here; cargo and rustc are provided by default
|
|
|
|
# from the toolchain that was specified earlier.
|
|
|
|
packages = [
|
2022-01-17 02:30:07 +03:00
|
|
|
];
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|