Skip to content

Experiment: publish crate to NPM using wasm-pack #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 65 additions & 12 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -8,6 +8,9 @@ readme = "README.md"
repository = "https://github.com/nix-community/rnix-parser"
version = "0.10.1"

[lib]
crate-type = ["cdylib", "rlib"]

[[bench]]
harness = false
name = "all-packages"
@@ -19,3 +22,4 @@ smol_str = "0.1.17"

[dev-dependencies]
criterion = "0.3.0"
wasm-bindgen-test = "0.3.29"
63 changes: 41 additions & 22 deletions flake.lock

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

97 changes: 42 additions & 55 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,63 +1,50 @@
{
description = "Rust-based parser for nix files";

# Stolen from https://gist.github.com/573/885a062ca49d2db355c22004cc395066
inputs = {
utils.url = "github:numtide/flake-utils";
nixpkgs.url = github:NixOS/nixpkgs/nixos-unstable;
import-cargo.url = github:edolstra/import-cargo;
nixpkgs = { url = "github:nixos/nixpkgs/nixos-unstable"; };
rust-overlay = { url = "github:oxalica/rust-overlay"; };
};

outputs = { self, nixpkgs, utils, import-cargo }:
outputs = { nixpkgs, rust-overlay, ... }:
let system = "x86_64-linux";
in
{
overlay = final: prev: let
target = final.rust.toRustTarget final.stdenv.hostPlatform;
flags = "--release --offline --target ${target}";
inherit (import-cargo.builders) importCargo;
in {
rnix-parser = final.stdenv.mkDerivation {
pname = "rnix-parser";
version = "0.9.1";
src = final.lib.cleanSource ./.;
nativeBuildInputs = with final; [
rustc cargo
(importCargo { lockFile = ./Cargo.lock; inherit (final) pkgs; }).cargoHome
];

outputs = [ "out" "doc" ];
doCheck = true;

buildPhase = ''
cargo build ${flags}
cargo doc ${flags}
'';

checkPhase = ''
cargo test ${flags}
cargo bench
'';

installPhase = ''
mkdir -p $out/lib
mkdir -p $doc/share/doc/rnix

cp -r ./target/${target}/doc $doc/share/doc/rnix
cp ./target/${target}/release/librnix.rlib $out/lib/
'';
};
};
}
// utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; overlays = [ self.overlay ]; };
in
rec {
# `nix develop`
devShell = pkgs.mkShell {
buildInputs = with pkgs; [ rustfmt rustc cargo ];
};

packages.rnix-parser = pkgs.rnix-parser;
defaultPackage = packages.rnix-parser;
}
);
devShell.${system} =
let
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlay ];
};
in
(({ pkgs, ... }:
pkgs.mkShell {
buildInputs = with pkgs; [
cargo
cargo-watch
nodejs
wasm-pack

# Note: to use stable, just replace `nightly` with `stable`
(rust-bin.stable.latest.default.override {
extensions = [ "rust-src" ];
targets = [ "wasm32-unknown-unknown" ];
})

# Add some extra dependencies from `pkgs`
pkg-config
openssl
];

shellHook = "";
}) {
pkgs = pkgs;

# Set Environment Variables
RUST_BACKTRACE = 1;
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
});
};
}