Skip to content

Commit 40475b1

Browse files
tmp
1 parent 9478990 commit 40475b1

File tree

5 files changed

+69
-39
lines changed

5 files changed

+69
-39
lines changed

.github/workflows/build-nix-package.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ jobs:
1616

1717
- name: Build Nix Package
1818
run: nix build .nix
19+
20+
build-without-resources:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: DeterminateSystems/nix-installer-action@main
27+
- uses: DeterminateSystems/magic-nix-cache-action@main
28+
29+
- name: Build Nix Package Without Resources
30+
run: nix build .nix#graphite-without-resources

.nix/flake.nix

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@
101101
{
102102
packages = rec {
103103
default = graphite;
104-
graphite = import ./pkgs/graphite.nix {
104+
graphite = (import ./pkgs/graphite.nix {
105105
pkgs = pkgs // { inherit graphene-raster-nodes-shaders; };
106106
inherit info inputs deps libs tools;
107-
};
107+
}) {};
108+
graphite-without-resources = (import ./pkgs/graphite.nix {
109+
pkgs = pkgs // { inherit graphene-raster-nodes-shaders; };
110+
inherit info inputs deps libs tools;
111+
}) { embeddedResources = false; };
108112
#TODO: graphene-cli = import ./pkgs/graphene-cli.nix { inherit info pkgs inputs deps libs tools; };
109113
graphene-raster-nodes-shaders = import ./pkgs/graphene-raster-nodes-shaders.nix { inherit info pkgs inputs deps libs tools; };
110114
};

.nix/pkgs/graphite.nix

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
{ info, pkgs, inputs, deps, libs, tools, ... }:
22

3+
{
4+
embeddedResources ? true,
5+
}:
6+
37
let
4-
cargoDeps = deps.crane.lib.buildDepsOnly {
5-
inherit (info) pname version src;
6-
strictDeps = true;
7-
buildInputs = libs.desktop-all;
8-
nativeBuildInputs = tools.desktop;
9-
};
10-
resources = deps.crane.lib.buildPackage {
8+
resourcesCommon = {
119
pname = "${info.pname}-resources";
1210
inherit (info) version src;
13-
14-
cargoArtifacts = cargoDeps;
15-
1611
strictDeps = true;
12+
doCheck = false;
13+
nativeBuildInputs = tools.frontend;
14+
cargoExtraArgs = "--target wasm32-unknown-unknown -p graphite-wasm --no-default-features --features native";
15+
};
16+
resources = deps.crane.lib.buildPackage (resourcesCommon // {
17+
cargoArtifacts = deps.crane.lib.buildDepsOnly resourcesCommon;
1718

1819
# TODO: Remove the need for this hash by using individual package resolutions and hashes from package-lock.json
1920
npmDeps = pkgs.fetchNpmDeps {
@@ -26,7 +27,6 @@ let
2627
npmConfigScript = "setup";
2728
makeCacheWritable = true;
2829

29-
buildInputs = libs.desktop-all;
3030
nativeBuildInputs = tools.frontend ++ [ pkgs.npmHooks.npmConfigHook ];
3131

3232
buildPhase = ''
@@ -41,28 +41,29 @@ let
4141
mkdir -p $out
4242
cp -r frontend/dist/* $out/
4343
'';
44-
44+
});
45+
common = {
46+
inherit (info) pname version src;
47+
strictDeps = true;
48+
buildInputs = libs.desktop-all;
49+
nativeBuildInputs = tools.desktop ++ [ pkgs.makeWrapper ];
50+
env = deps.cef.env;
4551
doCheck = false;
52+
cargoExtraArgs = "-p graphite-desktop${if embeddedResources then "" else " --no-default-features --features recommended"}";
4653
};
4754
in
4855

49-
deps.crane.lib.buildPackage {
50-
inherit (info) pname version src;
51-
52-
cargoArtifacts = cargoDeps;
53-
54-
strictDeps = true;
56+
deps.crane.lib.buildPackage (common // {
57+
cargoArtifacts = deps.crane.lib.buildDepsOnly common;
5558

56-
buildInputs = libs.desktop-all;
57-
nativeBuildInputs = tools.desktop;
58-
59-
env = deps.cef.env // {
60-
EMBEDDED_RESOURCES = resources;
59+
env = common.env // {
6160
GRAPHENE_RASTER_NODES_SHADER_PATH = pkgs.graphene-raster-nodes-shaders;
62-
};
61+
} // (if embeddedResources then {
62+
EMBEDDED_RESOURCES = resources;
63+
} else {});
6364

6465
buildPhase = ''
65-
cargo build -r -p graphite-desktop
66+
cargo build -r ${common.cargoExtraArgs}
6667
'';
6768

6869
installPhase = ''
@@ -76,11 +77,9 @@ deps.crane.lib.buildPackage {
7677
cp $src/desktop/assets/graphite-icon-color.svg $out/share/icons/hicolor/scalable/apps/
7778
'';
7879

79-
doCheck = false;
80-
8180
postFixup = ''
8281
wrapProgram "$out/bin/graphite" \
8382
--prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath libs.desktop-all}:${deps.cef.env.CEF_PATH}" \
8483
--set CEF_PATH "${deps.cef.env.CEF_PATH}"
8584
'';
86-
}
85+
})

desktop/assets/rs.graphite.GraphiteEditor.desktop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Name=Graphite
33
GenericName=Vector & Raster Graphics Editor
44
Comment=Open-source vector & raster graphics editor. Featuring node based procedural nondestructive editing workflow.
5-
Exec=graphite-editor
5+
Exec=graphite
66
Terminal=false
77
Type=Application
88
Icon=graphite-icon-color

desktop/embedded-resources/build.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1-
const RESOURCES: &str = "../../frontend/dist";
1+
const EMBEDDED_RESOURCES_ENV: &str = "EMBEDDED_RESOURCES";
2+
const DEFAULT_RESOURCES_DIR: &str = "../../frontend/dist";
23

3-
// Check if the directory `RESOURCES` exists and sets the embedded_resources cfg accordingly
4-
// Absolute path of `RESOURCES` available via the `EMBEDDED_RESOURCES` environment variable
54
fn main() {
6-
let crate_dir = std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
5+
let mut embedded_resources: Option<String> = None;
76

8-
println!("cargo:rerun-if-changed={RESOURCES}");
9-
if let Ok(resources) = crate_dir.join(RESOURCES).canonicalize()
10-
&& resources.exists()
7+
println!("cargo:rerun-if-env-changed={EMBEDDED_RESOURCES_ENV}");
8+
if let Ok(embedded_resources_env) = std::env::var(EMBEDDED_RESOURCES_ENV)
9+
&& std::path::PathBuf::from(&embedded_resources_env).exists()
1110
{
11+
embedded_resources = Some(embedded_resources_env);
12+
}
13+
14+
if embedded_resources.is_none() {
15+
// Check if the directory `DEFAULT_RESOURCES_DIR` exists and sets the embedded_resources cfg accordingly
16+
// Absolute path of `DEFAULT_RESOURCES_DIR` available via the `EMBEDDED_RESOURCES` environment variable
17+
let crate_dir = std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
18+
println!("cargo:rerun-if-changed={DEFAULT_RESOURCES_DIR}");
19+
if let Ok(resources) = crate_dir.join(DEFAULT_RESOURCES_DIR).canonicalize()
20+
&& resources.exists()
21+
{
22+
embedded_resources = Some(resources.to_string_lossy().to_string());
23+
}
24+
}
25+
26+
if let Some(embedded_resources) = embedded_resources {
1227
println!("cargo:rustc-cfg=embedded_resources");
13-
println!("cargo:rustc-env=EMBEDDED_RESOURCES={}", resources.to_string_lossy());
28+
println!("cargo:rustc-env={EMBEDDED_RESOURCES_ENV}={embedded_resources}");
1429
} else {
1530
println!("cargo:warning=Resource directory does not exist. Resources will not be embedded. Did you forget to build the frontend?");
1631
}

0 commit comments

Comments
 (0)