Skip to content

Commit d130a31

Browse files
committed
feat: add nix flake with devshell and build package
1 parent 655acc4 commit d130a31

File tree

4 files changed

+195
-1
lines changed

4 files changed

+195
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/target
2+
result

flake.lock

Lines changed: 130 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
4+
fenix.url = "github:nix-community/fenix";
5+
flake-utils.url = "github:numtide/flake-utils";
6+
crane = {
7+
url = "github:ipetkov/crane";
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
};
10+
};
11+
12+
outputs = {
13+
nixpkgs,
14+
flake-utils,
15+
crane,
16+
...
17+
} @ inputs:
18+
flake-utils.lib.eachSystem (flake-utils.lib.defaultSystems) (
19+
system: let
20+
pkgs = nixpkgs.legacyPackages.${system};
21+
lib = pkgs.lib;
22+
fenix = inputs.fenix.packages;
23+
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
24+
25+
# fenix: rustup replacement for reproducible builds
26+
toolchain = fenix.${system}.fromToolchainFile {
27+
file = ./rust-toolchain.toml;
28+
sha256 = "sha256-VZZnlyP69+Y3crrLHQyJirqlHrTtGTsyiSnZB8jEvVo=";
29+
};
30+
31+
# buildInputs for Examples
32+
buildInputs = with pkgs; [
33+
toolchain
34+
pkg-config
35+
];
36+
37+
zed-plugin = craneLib.buildPackage {
38+
doCheck = false;
39+
pname = "zed-dotenv";
40+
src = craneLib.cleanCargoSource (craneLib.path ./.);
41+
buildPhaseCargoCommand = "cargo build --release --target wasm32-wasip1";
42+
43+
installPhaseCommand = ''
44+
mkdir -p $out
45+
cp target/wasm32-wasip1/release/zed_dotenv.wasm $out/extension.wasm
46+
'';
47+
48+
inherit buildInputs;
49+
};
50+
in {
51+
# `nix build`
52+
packages.default = zed-plugin;
53+
# `nix develop`
54+
devShells.default = pkgs.mkShell {
55+
packages = with pkgs; buildInputs ++ [
56+
cargo-dist
57+
cargo-release
58+
];
59+
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
60+
};
61+
}
62+
);
63+
}

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
22
channel = "stable"
33
profile = "default"
4-
targets = ["wasm32-unknown-unknown"]
4+
targets = ["wasm32-wasip1"]

0 commit comments

Comments
 (0)