A high-performance inference engine for AI models
Nix hermetic build (#782)
uuuvn8bb4a2f3440c
diff --git a/Cargo.lock b/Cargo.lockindex fce9f3f95..2aefeaa2a 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1031,7 +1031,7 @@ version = "3.1.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34"dependencies = [- "windows-sys 0.61.2",+ "windows-sys 0.59.0",][[package]]@@ -1393,7 +1393,7 @@ checksum = "fb22e947478ccf9dc44d8922042c677a63fbb88f2cb468521d1145816e5087cb"[[package]]name = "cxx"version = "1.0.194"-source = "git+https://github.com/trymirai/cxx.git?branch=master#b616fe260d36353919d9f7e13754cd88064118a3"+source = "git+https://github.com/trymirai/cxx.git?branch=master#aefe85bdd845e391c68e5400e19bdb437502859d"dependencies = ["cxx-build","cxx-cc",@@ -1406,7 +1406,7 @@ dependencies = [[[package]]name = "cxx-build"version = "1.0.194"-source = "git+https://github.com/trymirai/cxx.git?branch=master#b616fe260d36353919d9f7e13754cd88064118a3"+source = "git+https://github.com/trymirai/cxx.git?branch=master#aefe85bdd845e391c68e5400e19bdb437502859d"dependencies = ["cc","codespan-reporting",@@ -1421,7 +1421,7 @@ dependencies = [[[package]]name = "cxx-cc"version = "1.0.194"-source = "git+https://github.com/trymirai/cxx.git?branch=master#b616fe260d36353919d9f7e13754cd88064118a3"+source = "git+https://github.com/trymirai/cxx.git?branch=master#aefe85bdd845e391c68e5400e19bdb437502859d"dependencies = ["cc","cxxbridge-flags",@@ -1430,7 +1430,7 @@ dependencies = [[[package]]name = "cxxbridge-cmd"version = "1.0.194"-source = "git+https://github.com/trymirai/cxx.git?branch=master#b616fe260d36353919d9f7e13754cd88064118a3"+source = "git+https://github.com/trymirai/cxx.git?branch=master#aefe85bdd845e391c68e5400e19bdb437502859d"dependencies = ["clap","codespan-reporting",@@ -1443,12 +1443,12 @@ dependencies = [[[package]]name = "cxxbridge-flags"version = "1.0.194"-source = "git+https://github.com/trymirai/cxx.git?branch=master#b616fe260d36353919d9f7e13754cd88064118a3"+source = "git+https://github.com/trymirai/cxx.git?branch=master#aefe85bdd845e391c68e5400e19bdb437502859d"[[package]]name = "cxxbridge-macro"version = "1.0.194"-source = "git+https://github.com/trymirai/cxx.git?branch=master#b616fe260d36353919d9f7e13754cd88064118a3"+source = "git+https://github.com/trymirai/cxx.git?branch=master#aefe85bdd845e391c68e5400e19bdb437502859d"dependencies = ["indexmap 2.14.0","proc-macro2",@@ -1703,7 +1703,7 @@ dependencies = ["libc","option-ext","redox_users",- "windows-sys 0.61.2",+ "windows-sys 0.59.0",][[package]]@@ -1849,7 +1849,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"dependencies = ["libc",- "windows-sys 0.61.2",+ "windows-sys 0.59.0",][[package]]@@ -2960,7 +2960,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46"dependencies = ["hermit-abi","libc",- "windows-sys 0.61.2",+ "windows-sys 0.59.0",][[package]]@@ -3908,7 +3908,7 @@ version = "0.50.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"dependencies = [- "windows-sys 0.61.2",+ "windows-sys 0.59.0",][[package]]@@ -4875,7 +4875,7 @@ dependencies = ["once_cell","socket2 0.6.4","tracing",- "windows-sys 0.61.2",+ "windows-sys 0.59.0",][[package]]@@ -5612,7 +5612,7 @@ dependencies = ["errno","libc","linux-raw-sys",- "windows-sys 0.61.2",+ "windows-sys 0.59.0",][[package]]@@ -5670,7 +5670,7 @@ dependencies = ["security-framework","security-framework-sys","webpki-root-certs",- "windows-sys 0.61.2",+ "windows-sys 0.59.0",][[package]]@@ -6516,7 +6516,7 @@ dependencies = ["getrandom 0.4.3","once_cell","rustix",- "windows-sys 0.61.2",+ "windows-sys 0.59.0",][[package]]@@ -7938,15 +7938,6 @@ dependencies = ["wezterm-dynamic",]-[[package]]-name = "which"-version = "8.0.5"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "8f3ef584124b911bcc3875c2f1472e80f24361ceb789bd1c62b3e9a3df9ff43c"-dependencies = [- "libc",-]-[[package]]name = "winapi"version = "0.3.9"@@ -7969,7 +7960,7 @@ version = "0.1.11"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"dependencies = [- "windows-sys 0.61.2",+ "windows-sys 0.59.0",][[package]]@@ -8378,7 +8369,7 @@ checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4"[[package]]name = "xgrammar-rs"version = "0.2.3"-source = "git+https://github.com/trymirai/xgrammar-rs.git?tag=0.2.3#e1e0f27df369c5d6027cc89ba4801fcda10e7b9e"+source = "git+https://github.com/trymirai/xgrammar-rs.git?branch=main#04995a307d58f3b2cd015cd5bfd4d7bbeab98f3e"dependencies = ["cc","cmake",@@ -8387,7 +8378,6 @@ dependencies = ["serde_json","tokenizers","walkdir",- "which",][[package]]diff --git a/Cargo.toml b/Cargo.tomlindex 10b24e976..6a394e1e0 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -25,7 +25,7 @@ resolver = "3"[workspace.package]edition = "2024"-rust-version = "1.94"+rust-version = "1.98"version = "0.5.22"authors = ["Mirai Tech Inc. <[email protected]>"]description = "A high-performance inference engine for AI models"@@ -62,7 +62,7 @@ keisoku = { path = "crates/legacy/keisoku", default-features = false }kanka = { path = "crates/legacy/kanka", default-features = false }kiban = { path = "crates/legacy/kiban", default-features = false }uzu = { path = "crates/legacy/uzu", default-features = false }-xgrammar = { package = "xgrammar-rs", git = "https://github.com/trymirai/xgrammar-rs.git", tag = "0.2.3", features = ["tokenizers"] }+xgrammar = { package = "xgrammar-rs", git = "https://github.com/trymirai/xgrammar-rs.git", branch = "main", features = ["tokenizers"] }half = { version = "2.7", features = ["bytemuck", "num-traits"] }ndarray = "0.17"serde = { version = "1.0", features = ["derive"] }diff --git a/flake.lock b/flake.lockindex 23adf7853..fb03a1543 100644--- a/flake.lock+++ b/flake.lock@@ -2,11 +2,11 @@"nodes": {"crane": {"locked": {- "lastModified": 1784564969,- "narHash": "sha256-TkTWNhJV/8Wk3czlbz4bwHZkFCaCHPsOy+oJe4PUiXg=",+ "lastModified": 1787326676,+ "narHash": "sha256-lWhBbBvC05/xwivKBBiM2YNizpmgqCgyOIzomvRuwxs=","owner": "ipetkov","repo": "crane",- "rev": "7930f6c291de6f83c257839d434592aa085f290a",+ "rev": "692f7e9ef2ece8125b466f66f2af532b3edaed0d","type": "github"},"original": {@@ -35,11 +35,11 @@},"nixpkgs": {"locked": {- "lastModified": 1784796856,- "narHash": "sha256-wWFrV5/Qbm+lyt5x20E/bSbfJiGKMo4RCxZV8cl/WZI=",+ "lastModified": 1787736819,+ "narHash": "sha256-cV5xEJJK3BvhU8rEd4mC9UsmDi5qscv/kzGPhBRC5WA=","owner": "nixos","repo": "nixpkgs",- "rev": "e2587caef70cea85dd97d7daab492899902dbf5d",+ "rev": "9fbb54b33e91ee4ca368e35a78e0613c720600b3","type": "github"},"original": {@@ -64,11 +64,11 @@]},"locked": {- "lastModified": 1785044261,- "narHash": "sha256-ehF/c4fLdgmNu7YXEClnmwhoBYddhYIVoSQpsZoorC4=",+ "lastModified": 1787834454,+ "narHash": "sha256-jXSvqn04IOecJCvSvl8+g3PsbDVNP6qKs6dKUs/b16k=","owner": "oxalica","repo": "rust-overlay",- "rev": "fe2124391e739e7b3e8720cd8a73f06edd0aceba",+ "rev": "dc2fd1acc537f3583744e1373597a5731ff7a6e3","type": "github"},"original": {diff --git a/flake.nix b/flake.nixindex c8f7239c4..155a9b7f3 100644--- a/flake.nix+++ b/flake.nix@@ -18,26 +18,85 @@}:flake-utils.lib.eachDefaultSystem (system: let- overlays = [(import rust-overlay)];pkgs = import nixpkgs {- inherit system overlays;+ inherit system;+ overlays = [(import rust-overlay)];};- lib = pkgs.lib;+rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;- nativeBuildInputs = with pkgs;- [- # for xgrammar-rs- cmake- ]- ++ (lib.optionals pkgs.stdenv.isDarwin [- # impure hack to get metal toolchain- (lib.hiPrio (writeShellScriptBin "xcrun" ''- unset DEVELOPER_DIR- exec /usr/bin/xcrun "$@"- ''))- ]);+ aar-extract = pkgs.ipsw.overrideAttrs (old: {+ pname = "aar-extract";+ postPatch =+ (old.postPatch or "")+ + ''+ mkdir -p cmd/aar-extract+ cat > cmd/aar-extract/main.go <<'EOF'+ package main++ import "io"+ import "os"+ import "path/filepath"+ import "github.com/blacktop/ipsw/pkg/ota"++ func main() {+ o, err := ota.Open(os.Args[1], &ota.Config{SymmetricKey: os.Getenv("AEA_KEY")})+ if err != nil {+ panic(err)+ }+ for _, f := range o.Files() {+ if f.IsDir() {+ continue+ }+ dst := filepath.Join(os.Args[2], f.Name())+ rc, err := f.Open(false)+ if err != nil {+ panic(err)+ }+ os.MkdirAll(filepath.Dir(dst), 0o755)+ out, _ := os.Create(dst)+ io.Copy(out, rc)+ rc.Close()+ out.Close()+ }+ }+ EOF+ '';+ subPackages = ["cmd/aar-extract"];+ ldflags = [];+ });++ metal-toolchain = pkgs.stdenvNoCC.mkDerivation {+ pname = "metal-toolchain";+ version = "17F109";++ src = pkgs.fetchurl {+ url = "https://updates.cdn-apple.com/2026MobileAssets/mobileassets/022-22264/722AB304-567A-4611-A7CA-1A94FA951B0B/com_apple_MobileAsset_MetalToolchain/78ED9FD0-8B39-4EEF-B0EE-67013D77BE16.aar";+ hash = "sha256-UraVdUkU0VDWMP4UnKzHam1yBS1qYtqx8rkvPmgmelY=";+ };+ dontUnpack = true;++ nativeBuildInputs = with pkgs; [aar-extract _7zz];++ buildPhase = ''+ mkdir aar dmg+ AEA_KEY='iOd2WvA6GXSJJrdQkp/vj1nP6FyjxkWe9JZwvJyG71E=' aar-extract "$src" aar+ 7zz x -y aar/AssetData/Restore/022-21788-058.dmg -odmg+ '';++ installPhase = ''+ cp -r dmg/Metal.xctoolchain/ "$out"/+ ln -s usr/bin "$out"/bin+ '';++ meta = {+ platforms = ["aarch64-darwin" "x86_64-darwin"];+ };+ };++ buildInputs = with pkgs; (lib.optionals pkgs.stdenv.hostPlatform.isLinux [pkg-config alsa-lib]) ++ (lib.optionals pkgs.stdenv.hostPlatform.isDarwin [apple-sdk_26]);+ nativeBuildInputs = with pkgs; [cmake] ++ (lib.optionals pkgs.stdenv.hostPlatform.isDarwin [metal-toolchain]);mirai = craneLib.buildPackage {pname = "mirai";@@ -49,7 +108,8 @@install -Dm755 target/release/cli $out/bin/mirai'';- inherit nativeBuildInputs;+ nativeBuildInputs = nativeBuildInputs ++ (with pkgs; (lib.optionals pkgs.stdenv.hostPlatform.isDarwin [writableTmpDirAsHomeHook]));+ inherit buildInputs;doCheck = false;};@@ -61,11 +121,11 @@default = mirai;};- devShells.default = pkgs.mkShell ({+ devShells.default = pkgs.mkShell {nativeBuildInputs =nativeBuildInputs++ (with pkgs; [- nixd+ niluvwasmtimeevcxr@@ -77,17 +137,9 @@cargo-flamegraphcargo-show-asmcritcmp- ])- ++ (lib.optionals pkgs.stdenv.isLinux (with pkgs; [- pkg-config- openssl- alsa-lib- clang- ]));- }- // (lib.optionalAttrs pkgs.stdenv.isLinux {- LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";- }));+ ]);+ inherit buildInputs;+ };});}