From 75c3a53c2a6c2b9f5e06442e97141e64895edd9c Mon Sep 17 00:00:00 2001 From: firestar99 Date: Sun, 5 Oct 2025 12:40:33 +0200 Subject: [PATCH 1/3] update cargo-gpu, remove legacy-target-specs to fix nix builds --- Cargo.lock | 18 +++++++++--------- Cargo.toml | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae28a7bccb..63b4473f3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -648,17 +648,17 @@ dependencies = [ [[package]] name = "cargo-gpu" version = "0.1.0" -source = "git+https://github.com/rust-gpu/cargo-gpu?rev=f969528e87baa17a7d48eecf4a6fcfdcaaf30566#f969528e87baa17a7d48eecf4a6fcfdcaaf30566" +source = "git+https://github.com/rust-gpu/cargo-gpu?rev=1358ab005b9a6b076117ef35f9de597c64f85670#1358ab005b9a6b076117ef35f9de597c64f85670" dependencies = [ "anyhow", "cargo_metadata", "clap", "crossterm", "directories", + "dunce", "env_logger", "log", "relative-path", - "rustc_codegen_spirv-target-specs 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver", "serde", "serde_json", @@ -1322,6 +1322,12 @@ dependencies = [ "serde", ] +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + [[package]] name = "dyn-any" version = "0.3.1" @@ -4783,12 +4789,6 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" -[[package]] -name = "rustc_codegen_spirv-target-specs" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c89eaf493b3dfc730cda42a77014aad65e03213992c7afe0dff60a9f7d3dd94" - [[package]] name = "rustc_codegen_spirv-target-specs" version = "0.9.0" @@ -5334,7 +5334,7 @@ dependencies = [ "memchr", "notify", "raw-string", - "rustc_codegen_spirv-target-specs 0.9.0 (git+https://github.com/rust-gpu/rust-gpu?rev=c12f216121820580731440ee79ebc7403d6ea04f)", + "rustc_codegen_spirv-target-specs", "rustc_codegen_spirv-types", "semver", "serde", diff --git a/Cargo.toml b/Cargo.toml index 73f856eea6..d1505b2d1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -196,7 +196,7 @@ poly-cool = "0.3" spin = "0.10" clap = "4.5" spirv-std = { git = "https://github.com/rust-gpu/rust-gpu", rev = "c12f216121820580731440ee79ebc7403d6ea04f", features = ["bytemuck"] } -cargo-gpu = { git = "https://github.com/rust-gpu/cargo-gpu", rev = "f969528e87baa17a7d48eecf4a6fcfdcaaf30566" } +cargo-gpu = { git = "https://github.com/rust-gpu/cargo-gpu", rev = "1358ab005b9a6b076117ef35f9de597c64f85670", default-features = false } [workspace.lints.rust] unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spirv"))'] } From 63cb122c4d70d21024308aef7495b68675eb1fe4 Mon Sep 17 00:00:00 2001 From: Timon Schelling Date: Sun, 5 Oct 2025 20:04:45 +0000 Subject: [PATCH 2/3] add nix package to flake --- .nix/cef.nix | 33 ++++++++ .nix/flake.nix | 182 ++++++++++++++++++++---------------------- .nix/rust-gpu.nix | 41 ++++++++++ frontend/package.json | 4 +- 4 files changed, 162 insertions(+), 98 deletions(-) create mode 100644 .nix/cef.nix create mode 100644 .nix/rust-gpu.nix diff --git a/.nix/cef.nix b/.nix/cef.nix new file mode 100644 index 0000000000..00fb054ee6 --- /dev/null +++ b/.nix/cef.nix @@ -0,0 +1,33 @@ +{ pkgs }: + +let + libcef = pkgs.libcef.overrideAttrs (finalAttrs: previousAttrs: { + version = "139.0.17"; + gitRevision = "6c347eb"; + chromiumVersion = "139.0.7258.31"; + srcHash = "sha256-kRMO8DP4El1qytDsAZBdHvR9AAHXce90nPdyfJailBg="; + + __intentionallyOverridingVersion = true; + + postInstall = '' + strip $out/lib/* + ''; + }); + cefPath = pkgs.runCommand "cef-path" {} '' + mkdir -p $out + + ln -s ${libcef}/include $out/include + find ${libcef}/lib -type f -name "*" -exec ln -s {} $out/ \; + find ${libcef}/libexec -type f -name "*" -exec ln -s {} $out/ \; + cp -r ${libcef}/share/cef/* $out/ + + echo '${builtins.toJSON { + type = "minimal"; + name = builtins.baseNameOf libcef.src.url; + sha1 = ""; + }}' > $out/archive.json + ''; +in +{ + CEF_PATH = cefPath; +} diff --git a/.nix/flake.nix b/.nix/flake.nix index 03539534e7..43239c60e4 100644 --- a/.nix/flake.nix +++ b/.nix/flake.nix @@ -12,8 +12,6 @@ # - Development shell: `nix develop .nix` from the project root # - Run in dev shell with direnv: add `use flake` to .envrc { - description = "Development environment and build configuration"; - inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; rust-overlay = { @@ -40,85 +38,22 @@ extensions = rustExtensions; }; - rustGPUToolchainPkg = pkgs.rust-bin.nightly."2025-06-23".default.override { - extensions = rustExtensions ++ [ "rustc-dev" "llvm-tools" ]; - }; - rustGPUToolchainRustPlatform = pkgs.makeRustPlatform { - cargo = rustGPUToolchainPkg; - rustc = rustGPUToolchainPkg; - }; - rustc_codegen_spirv = rustGPUToolchainRustPlatform.buildRustPackage (finalAttrs: { - pname = "rustc_codegen_spirv"; - version = "0-unstable-2025-08-04"; - src = pkgs.fetchFromGitHub { - owner = "Rust-GPU"; - repo = "rust-gpu"; - rev = "c12f216121820580731440ee79ebc7403d6ea04f"; - hash = "sha256-rG1cZvOV0vYb1dETOzzbJ0asYdE039UZImobXZfKIno="; - }; - cargoHash = "sha256-AEigcEc5wiBd3zLqWN/2HSbkfOVFneAqNvg9HsouZf4="; - cargoBuildFlags = [ "-p" "rustc_codegen_spirv" "--features=use-compiled-tools" "--no-default-features" ]; - doCheck = false; - }); - rustGpuCargo = pkgs.writeShellScriptBin "cargo" '' - #!${pkgs.lib.getExe pkgs.bash} - - filtered_args=() - for arg in "$@"; do - case "$arg" in - +nightly|+nightly-*) ;; - *) filtered_args+=("$arg") ;; - esac - done - - exec ${rustGPUToolchainPkg}/bin/cargo ${"\${filtered_args[@]}"} - ''; - rustGpuPathOverride = "${rustGpuCargo}/bin:${rustGPUToolchainPkg}/bin"; - - libcef = pkgs.libcef.overrideAttrs (finalAttrs: previousAttrs: { - version = "139.0.17"; - gitRevision = "6c347eb"; - chromiumVersion = "139.0.7258.31"; - srcHash = "sha256-kRMO8DP4El1qytDsAZBdHvR9AAHXce90nPdyfJailBg="; - - __intentionallyOverridingVersion = true; - - postInstall = '' - strip $out/lib/* - ''; - }); - libcefPath = pkgs.runCommand "libcef-path" {} '' - mkdir -p $out - - ln -s ${libcef}/include $out/include - find ${libcef}/lib -type f -name "*" -exec ln -s {} $out/ \; - find ${libcef}/libexec -type f -name "*" -exec ln -s {} $out/ \; - cp -r ${libcef}/share/cef/* $out/ - - echo '${builtins.toJSON { - type = "minimal"; - name = builtins.baseNameOf libcef.src.url; - sha1 = ""; - }}' > $out/archive.json - ''; - - # Shared build inputs - system libraries that need to be in LD_LIBRARY_PATH - buildInputs = with pkgs; [ - # System libraries - wayland - openssl - vulkan-loader - libraw - libGL + # Shared build inputs; libraries that need to be in LD_LIBRARY_PATH + buildInputs = [ + pkgs.wayland + pkgs.openssl + pkgs.vulkan-loader + pkgs.libraw + pkgs.libGL # X11 libraries, not needed on wayland! Remove when x11 is finally dead - libxkbcommon - xorg.libXcursor - xorg.libxcb - xorg.libX11 + pkgs.libxkbcommon + pkgs.xorg.libXcursor + pkgs.xorg.libxcb + pkgs.xorg.libX11 ]; - # Development tools that don't need to be in LD_LIBRARY_PATH + # Packages needed to build the package buildTools = [ rust pkgs.nodejs @@ -127,40 +62,95 @@ pkgs.wasm-bindgen-cli pkgs.wasm-pack pkgs.pkg-config - pkgs.git pkgs.cargo-about + ]; + + # Development tools; not needed to build the package + devTools = [ + pkgs.git + + pkgs.cargo-watch + pkgs.cargo-nextest + pkgs.cargo-expand # Linker pkgs.mold - ]; - # Development tools that don't need to be in LD_LIBRARY_PATH - devTools = with pkgs; [ - cargo-watch - cargo-nextest - cargo-expand # Profiling tools - gnuplot - samply - cargo-flamegraph + pkgs.gnuplot + pkgs.samply + pkgs.cargo-flamegraph ]; + + cefEnv = import ./cef.nix { inherit pkgs; }; + rustGPUEnv = import ./rust-gpu.nix { inherit pkgs; }; + + libPath = "${pkgs.lib.makeLibraryPath buildInputs}:${cefEnv.CEF_PATH}"; in { - # Development shell configuration - devShells.default = pkgs.mkShell { + devShells.default = pkgs.mkShell ({ packages = buildInputs ++ buildTools ++ devTools; - LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath buildInputs}:${libcefPath}"; - CEF_PATH = libcefPath; - XDG_DATA_DIRS="${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS"; - - RUST_GPU_PATH_OVERRIDE = rustGpuPathOverride; - RUSTC_CODEGEN_SPIRV_PATH = "${rustc_codegen_spirv}/lib/librustc_codegen_spirv.so"; + LD_LIBRARY_PATH = libPath; + XDG_DATA_DIRS = "${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS"; shellHook = '' alias cargo='mold --run cargo' ''; - }; + } // cefEnv // rustGPUEnv); + + packages.default = pkgs.stdenv.mkDerivation(finalAttrs: { + pname = "graphite-editor"; + version = "unstable"; + src = pkgs.lib.cleanSource ./..; + + cargoDeps = pkgs.rustPlatform.fetchCargoVendor { + src = finalAttrs.src; + hash = "sha256-N9pMv9MvF3Z/yNjuSJtVHa1qBy9JmGvFV5jAriTQMaY="; + }; + + npmDeps = pkgs.fetchNpmDeps { + inherit (finalAttrs) pname version; + src = "${finalAttrs.src}/frontend"; + hash = "sha256-UWuJpKNYj2Xn34rpMDZ75pzMYUOLQjPeGuJ/QlPbX9A="; + }; + + npmRoot = "frontend"; + npmConfigScript = "setup"; + makeCacheWritable = true; + + buildInputs = buildInputs; + nativeBuildInputs = buildTools ++ [ + pkgs.rustPlatform.cargoSetupHook + pkgs.npmHooks.npmConfigHook + pkgs.makeWrapper + ]; + + env = cefEnv // rustGPUEnv; + + buildPhase = '' + export HOME="$TMPDIR" + + npm run build-desktop + ''; + + installPhase = '' + mkdir -p $out/bin + cp target/release/graphite-desktop $out/bin/graphite-editor + + mkdir -p $out/share/applications + cp $src/desktop/assets/*.desktop $out/share/applications/ + + mkdir -p $out/share/icons/hicolor/scalable/apps + cp $src/desktop/assets/graphite-icon-color.svg $out/share/icons/hicolor/scalable/apps/ + ''; + + postFixup = '' + wrapProgram "$out/bin/graphite-editor" \ + --prefix LD_LIBRARY_PATH : "${libPath}" \ + --set CEF_PATH "${cefEnv.CEF_PATH}" + ''; + }); } ); } diff --git a/.nix/rust-gpu.nix b/.nix/rust-gpu.nix new file mode 100644 index 0000000000..7f92e06732 --- /dev/null +++ b/.nix/rust-gpu.nix @@ -0,0 +1,41 @@ +{ pkgs }: + +let + toolchainPkg = pkgs.rust-bin.nightly."2025-06-23".default.override { + extensions = [ "rust-src" "rust-analyzer" "clippy" "cargo" "rustc-dev" "llvm-tools" ]; + }; + toolchainRustPlatform = pkgs.makeRustPlatform { + cargo = toolchainPkg; + rustc = toolchainPkg; + }; + rustc_codegen_spirv = toolchainRustPlatform.buildRustPackage (finalAttrs: { + pname = "rustc_codegen_spirv"; + version = "0-unstable-2025-08-04"; + src = pkgs.fetchFromGitHub { + owner = "Rust-GPU"; + repo = "rust-gpu"; + rev = "c12f216121820580731440ee79ebc7403d6ea04f"; + hash = "sha256-rG1cZvOV0vYb1dETOzzbJ0asYdE039UZImobXZfKIno="; + }; + cargoHash = "sha256-AEigcEc5wiBd3zLqWN/2HSbkfOVFneAqNvg9HsouZf4="; + cargoBuildFlags = [ "-p" "rustc_codegen_spirv" "--features=use-compiled-tools" "--no-default-features" ]; + doCheck = false; + }); + cargoWrapper = pkgs.writeShellScriptBin "cargo" '' + #!${pkgs.lib.getExe pkgs.bash} + + filtered_args=() + for arg in "$@"; do + case "$arg" in + +nightly|+nightly-*) ;; + *) filtered_args+=("$arg") ;; + esac + done + + exec ${toolchainPkg}/bin/cargo ${"\${filtered_args[@]}"} + ''; +in +{ + RUST_GPU_PATH_OVERRIDE = "${cargoWrapper}/bin:${toolchainPkg}/bin"; + RUSTC_CODEGEN_SPIRV_PATH = "${rustc_codegen_spirv}/lib/librustc_codegen_spirv.so"; +} diff --git a/frontend/package.json b/frontend/package.json index 6c65a88fea..e386458848 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -21,8 +21,8 @@ "lint-fix": "eslint . --fix && tsc --noEmit", "---------- INTERNAL ----------": "", "setup": "node package-installer.js", - "native:build-dev": "wasm-pack build ./wasm --dev --target=web --features native", - "native:build-production": "wasm-pack build ./wasm --release --target=web --features native", + "native:build-dev": "wasm-pack build ./wasm --dev --target=web --no-default-features --features native", + "native:build-production": "wasm-pack build ./wasm --release --target=web --no-default-features --features native", "wasm:build-dev": "wasm-pack build ./wasm --dev --target=web", "wasm:build-profiling": "wasm-pack build ./wasm --profiling --target=web", "wasm:build-production": "wasm-pack build ./wasm --release --target=web", From 08d87bbaee2b6d6105c24a91f3930e5f937b51c7 Mon Sep 17 00:00:00 2001 From: Timon Schelling Date: Tue, 7 Oct 2025 13:59:09 +0000 Subject: [PATCH 3/3] update cargo hash --- .nix/flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nix/flake.nix b/.nix/flake.nix index 43239c60e4..5ef0f63c7d 100644 --- a/.nix/flake.nix +++ b/.nix/flake.nix @@ -106,7 +106,7 @@ cargoDeps = pkgs.rustPlatform.fetchCargoVendor { src = finalAttrs.src; - hash = "sha256-N9pMv9MvF3Z/yNjuSJtVHa1qBy9JmGvFV5jAriTQMaY="; + hash = "sha256-BVIQIZbGW19Rof0J7U2r6XFCUC52hb7+uaE1di4bV4A="; }; npmDeps = pkgs.fetchNpmDeps {