Skip to content

Commit

Permalink
add nix flake for building on nixos
Browse files Browse the repository at this point in the history
  • Loading branch information
tijlleenders committed Nov 3, 2024
1 parent 8119f8a commit 36f5636
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 118 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
4 changes: 3 additions & 1 deletion Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ debug = false
# Tell `rustc` to optimize for small code size s or speed 2 / 3.
opt-level = 3

[package.metadata.wasm-pack.profile.release]
wasm-opt = ["-O4", "--enable-bulk-memory"]

[dependencies]
serde_json = "1.0.132"
serde = { version = "1.0.213", features = ["derive"] }
chrono = { version = "0.4.38", features = ["wasmbind", "serde"] }
lazy_static = "1.5.0"

# simple WASM codegen
wasm-bindgen = { version = "0.2.92" }
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
# instead of wasm-bindgen::serde-serialize feature that may lead to a cyclic package dependency
serde-wasm-bindgen = "0.6.5"

Expand Down
100 changes: 100 additions & 0 deletions flake.lock

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

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

outputs = { self, nixpkgs, fenix, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
toolchain = with fenix.packages.${system}; combine [
complete.toolchain
targets.wasm32-unknown-unknown.latest.rust-std
];
in
{
devShells.default = pkgs.mkShell {
buildInputs = [
toolchain
pkgs.wasm-pack
pkgs.rust-analyzer
] ++ (with pkgs; [
pkg-config
openssl
# Add LLVM tools for WASM linking
llvmPackages.bintools
]);

RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
# Set the linker for WASM
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "lld";
};
}
);
}
5 changes: 3 additions & 2 deletions pkg/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "zinzen",
"type": "module",
"description": "Algorithm for auto-scheduling time-constrained tasks on a timeline",
"version": "0.2.0",
"version": "0.2.1",
"license": "AGPL-3.0-or-later",
"repository": {
"type": "git",
Expand All @@ -13,7 +14,7 @@
"scheduler.d.ts",
"LICENSE.md"
],
"module": "scheduler.js",
"main": "scheduler.js",
"homepage": "https://github.com/tijlleenders/ZinZen-scheduler",
"types": "scheduler.d.ts",
"sideEffects": [
Expand Down
7 changes: 5 additions & 2 deletions pkg/scheduler.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl

export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly schedule: (a: number, b: number) => void;
readonly schedule: (a: number) => Array;
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly __wbindgen_export_2: WebAssembly.Table;
readonly __externref_table_dealloc: (a: number) => void;
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
readonly __wbindgen_exn_store: (a: number) => void;
readonly __externref_table_alloc: () => number;
readonly __wbindgen_start: () => void;
}

export type SyncInitInput = BufferSource | WebAssembly.Module;
Expand Down
Loading

0 comments on commit 36f5636

Please sign in to comment.