on master help sign in
Add 'enableWasm' flag, and combine ghcjs/wasm assets in one place
commit6a87bd4893484266f85fd8d4ad488423082e7e1d authorDivam <dfordivam@gmail.com> dateWed 8 Apr 2020, 15:09 (7 years ago) parentc7d188e
2 files changed+15−13
default.nix+14−12 lib/backend/src/Obelisk/Backend.hs+1−1
default.nix+14−12
@@ -2,6 +2,7 @@
22, profiling ? false
33, iosSdkVersion ? "10.2"
44, config ? {}
5+, enableWasm ? true
56, reflex-platform-func ? import ./dep/reflex-platform
67}:
78let
@@ -32,7 +33,7 @@ let
3233 # Development environments for obelisk packages.
3334 ghcObeliskEnvs = pkgs.lib.mapAttrs (n: v: reflex-platform.workOn ghcObelisk v) ghcObelisk;
3435
35− inherit (import ./lib/asset/assets.nix { inherit nixpkgs; }) mkAssets mkAssetsWith gzipEncodings;
36+ inherit (import ./lib/asset/assets.nix { inherit nixpkgs; }) mkAssets;
3637
3738 haskellLib = pkgs.haskell.lib;
3839
@@ -95,14 +96,17 @@ in rec {
9596 chmod u+rw frontend.wasm
9697 chmod a-x frontend.wasm
9798 ${pkgs.wabt}/bin/wasm-strip frontend.wasm
98− chmod u-r frontend.wasm
9999 '';
100− wasm-assets = frontend : pkgs.runCommand "wasm-assets" {} ''
100+
101+ combinedJsWasmAssets = frontendJs: optimizationLevel: frontendWasm: pkgs.runCommand "combinedJsWasmAssets" {} ''
101102 mkdir $out
102103 cd $out
103− cp ${stripWasm frontend}/frontend.wasm $out/frontend.wasm
104− cp ${webabi}/lib/node_modules/webabi/jsaddleJS/* $out/
105− cp ${webabi}/lib/node_modules/webabi/build/worker_runner.js $out/worker_runner.js
104+ ln -s ${compressedJs frontendJs optimizationLevel}/* .
105+ ${if frontendWasm != null then ''
106+ ln -s ${stripWasm frontendWasm}/* .
107+ ln -s ${webabi}/lib/node_modules/webabi/jsaddleJS/* .
108+ ln -s ${webabi}/lib/node_modules/webabi/build/worker_runner.js .
109+ '' else '' ''}
106110 '';
107111
108112 serverModules = {
@@ -184,17 +188,15 @@ in rec {
184188 };
185189 };
186190
187− inherit mkAssets mkAssetsWith gzipEncodings;
191+ inherit mkAssets;
188192
189− # TODO add ghcjs back
190− # XXX the gzipEncodings helps faster debug cycles, use zopfliEncodings for best size
191− serverExe = backend: frontend: assets: optimizationLevel: wasm-frontend: version:
193+ serverExe = backend: frontendJs: assets: optimizationLevel: frontendWasm: version:
192194 pkgs.runCommand "serverExe" {} ''
193195 mkdir $out
194196 set -eux
195197 ln -s "${if profiling then backend else haskellLib.justStaticExecutables backend}"/bin/* $out/
196198 ln -s "${mkAssets assets}" $out/static.assets
197− ln -s ${mkAssetsWith gzipEncodings (wasm-assets wasm-frontend)} $out/frontend.wasm.assets
199+ ln -s ${mkAssets (combinedJsWasmAssets frontendJs optimizationLevel frontendWasm)} $out/frontend.jsexe.assets
198200 echo ${version} > $out/version
199201 '';
200202
@@ -327,7 +329,7 @@ in rec {
327329 mainProjectOut.ghcjs.frontend
328330 projectInst.passthru.staticFiles
329331 projectInst.passthru.__closureCompilerOptimizationLevel
330− mainProjectOut.wasm.frontend
332+ (if enableWasm then mainProjectOut.wasm.frontend else null)
331333 version;
332334 linuxExe = serverOn (projectOut { system = "x86_64-linux"; });
333335 dummyVersion = "Version number is only available for deployments";
lib/backend/src/Obelisk/Backend.hs+1−1
@@ -139,7 +139,7 @@ defaultStaticAssets = StaticAssets
139139
140140defaultFrontendGhcjsAssets :: StaticAssets
141141defaultFrontendGhcjsAssets = StaticAssets
142− { _staticAssets_processed = "frontend.wasm.assets"
142+ { _staticAssets_processed = "frontend.jsexe.assets"
143143 , _staticAssets_unprocessed = "frontend.jsexe"
144144 }
145145