Skip to content

Commit

Permalink
feat: add nix flake with devshell and build package
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera committed Sep 26, 2024
1 parent 655acc4 commit d130a31
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
result
130 changes: 130 additions & 0 deletions flake.lock

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

63 changes: 63 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
fenix.url = "github:nix-community/fenix";
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = {
nixpkgs,
flake-utils,
crane,
...
} @ inputs:
flake-utils.lib.eachSystem (flake-utils.lib.defaultSystems) (
system: let
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
fenix = inputs.fenix.packages;
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;

# fenix: rustup replacement for reproducible builds
toolchain = fenix.${system}.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-VZZnlyP69+Y3crrLHQyJirqlHrTtGTsyiSnZB8jEvVo=";
};

# buildInputs for Examples
buildInputs = with pkgs; [
toolchain
pkg-config
];

zed-plugin = craneLib.buildPackage {
doCheck = false;
pname = "zed-dotenv";
src = craneLib.cleanCargoSource (craneLib.path ./.);
buildPhaseCargoCommand = "cargo build --release --target wasm32-wasip1";

installPhaseCommand = ''
mkdir -p $out
cp target/wasm32-wasip1/release/zed_dotenv.wasm $out/extension.wasm
'';

inherit buildInputs;
};
in {
# `nix build`
packages.default = zed-plugin;
# `nix develop`
devShells.default = pkgs.mkShell {
packages = with pkgs; buildInputs ++ [
cargo-dist
cargo-release
];
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
};
}
);
}
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "stable"
profile = "default"
targets = ["wasm32-unknown-unknown"]
targets = ["wasm32-wasip1"]

0 comments on commit d130a31

Please sign in to comment.