Skip to content

Commit 3d3dd2e

Browse files
committed
Fixes for wasm TH
1 parent 4a63a2f commit 3d3dd2e

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

builder/ghc-for-component-wrapper.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ let
132132
ln -s $wrappedGhc/bin/${ghcCommand}-iserv $wrappedGhc/bin/ghc-iserv
133133
ln -s $wrappedGhc/bin/${ghcCommand}-iserv-prof $wrappedGhc/bin/ghc-iserv-prof
134134
''
135+
# These scripts break if symlinked (they check import.meta.filename against args)
136+
+ lib.optionalString (stdenv.hostPlatform.isWasm) ''
137+
rm $wrappedGhc/lib/*.mjs
138+
cp $unwrappedGhc/lib/*.mjs $wrappedGhc/lib/
139+
''
135140
# Wrap haddock, if the base GHC provides it.
136141
+ ''
137142
if [[ -x "${haddock}/bin/haddock" ]]; then

compiler/ghc/default.nix

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ let
128128
targetPackages.buildPackages.llvmPackages.llvm
129129
targetPackages.buildPackages.binaryen
130130
];
131-
outputs = ["dev" "out"];
131+
outputs = ["out" "dev"];
132132
NIX_NO_SELF_RPATH = true;
133133
} ''
134134
mkdir cbits
@@ -147,6 +147,11 @@ let
147147
wasm-opt --low-memory-unused --converge --debuginfo --flatten --rereloop --gufa -O4 -Oz libffi.so -o $out/lib/libffi.so
148148
'';
149149

150+
lib-wasm = buildPackages.symlinkJoin {
151+
name = "lib-wasm";
152+
paths = [ targetPackages.wasilibc libffi-wasm ];
153+
};
154+
150155
# TODO check if this possible fix for segfaults works or not.
151156
targetLibffi =
152157
# on native platforms targetPlatform.{libffi, gmp} do not exist; thus fall back
@@ -589,21 +594,27 @@ haskell-nix.haskellLib.makeCompilerDeps (stdenv.mkDerivation (rec {
589594
configurePlatforms = [ "build" "host" ] ++ lib.optional (!targetPlatform.isGhcjs) "target";
590595

591596
enableParallelBuilding = true;
592-
postPatch = lib.optionalString (targetPlatform.isWasm) ''
597+
postPatch = ''
598+
patchShebangs .
599+
'' + lib.optionalString (targetPlatform.isWasm) ''
593600
substituteInPlace utils/jsffi/dyld.mjs \
594601
--replace-fail \
595-
"node --disable-warning=ExperimentalWarning --experimental-wasm-type-reflection --no-turbo-fast-api-calls --wasm-lazy-validation" \
602+
"${buildPackages.nodejs-with-lto}/bin/node --disable-warning=ExperimentalWarning --experimental-wasm-type-reflection --no-turbo-fast-api-calls --wasm-lazy-validation" \
596603
"${buildPackages.writeShellScriptBin "node" ''
604+
SCRIPT=$1
605+
shift
606+
LIB_WASM=$1
607+
shift
597608
exec ${buildPackages.nodejs-with-lto}/bin/node \
598609
--disable-warning=ExperimentalWarning \
599610
--experimental-wasm-type-reflection \
600611
--no-turbo-fast-api-calls \
601612
--wasm-lazy-validation \
613+
"$SCRIPT" \
614+
"${lib-wasm}/lib" \
602615
"$@"
603616
''
604-
}"
605-
'' + ''
606-
patchShebangs .
617+
}/bin/node"
607618
'';
608619

609620
outputs = [ "out" "doc" "generated" ];

0 commit comments

Comments
 (0)