|
20 | 20 | flake-utils.lib.eachDefaultSystem ( |
21 | 21 | system: |
22 | 22 | let |
23 | | - # Overlay to patch Go to always use Fetch API in WASM |
24 | | - goWasmFetchOverlay = final: prev: { |
25 | | - go_1_24 = prev.go_1_24.overrideAttrs (oldAttrs: { |
26 | | - patches = (oldAttrs.patches or [ ]) ++ [ |
27 | | - (final.writeText "go-wasm-always-use-fetch.patch" '' |
28 | | - --- a/src/net/http/roundtrip_js.go |
29 | | - +++ b/src/net/http/roundtrip_js.go |
30 | | - @@ -13,7 +13,6 @@ import ( |
31 | | - "io" |
32 | | - "net/http/internal/ascii" |
33 | | - "strconv" |
34 | | - - "strings" |
35 | | - "syscall/js" |
36 | | - ) |
37 | | - |
38 | | - @@ -56,8 +55,8 @@ var jsFetchMissing = js.Global().Get("fetch").IsUndefined() |
39 | | - // |
40 | | - // TODO(go.dev/issue/60810): See if it's viable to test the Fetch API |
41 | | - // code path. |
42 | | - -var jsFetchDisabled = js.Global().Get("process").Type() == js.TypeObject && |
43 | | - - strings.HasPrefix(js.Global().Get("process").Get("argv0").String(), "node") |
44 | | - +// Patched to always use Fetch API for better WASM compatibility in Node.js |
45 | | - +var jsFetchDisabled = false |
46 | | - |
47 | | - // RoundTrip implements the [RoundTripper] interface using the WHATWG Fetch API. |
48 | | - func (t *Transport) RoundTrip(req *Request) (*Response, error) { |
49 | | - '') |
50 | | - ]; |
51 | | - }); |
52 | | - }; |
53 | | - |
54 | | - # Apply overlay to get patched Go |
| 23 | + # Import nixpkgs without any overlays |
55 | 24 | pkgs = import nixpkgs { |
56 | 25 | inherit system; |
57 | | - overlays = [ goWasmFetchOverlay ]; |
58 | 26 | }; |
59 | 27 |
|
| 28 | + # Use regular Go for everything except WASM builds |
60 | 29 | go = pkgs.go_1_24; |
| 30 | + |
| 31 | + # Create patched Go specifically for WASM builds |
| 32 | + goWasm = go.overrideAttrs (oldAttrs: { |
| 33 | + patches = (oldAttrs.patches or [ ]) ++ [ |
| 34 | + (pkgs.writeText "go-wasm-always-use-fetch.patch" '' |
| 35 | + --- a/src/net/http/roundtrip_js.go |
| 36 | + +++ b/src/net/http/roundtrip_js.go |
| 37 | + @@ -13,7 +13,6 @@ import ( |
| 38 | + "io" |
| 39 | + "net/http/internal/ascii" |
| 40 | + "strconv" |
| 41 | + - "strings" |
| 42 | + "syscall/js" |
| 43 | + ) |
| 44 | + |
| 45 | + @@ -56,8 +55,8 @@ var jsFetchMissing = js.Global().Get("fetch").IsUndefined() |
| 46 | + // |
| 47 | + // TODO(go.dev/issue/60810): See if it's viable to test the Fetch API |
| 48 | + // code path. |
| 49 | + -var jsFetchDisabled = js.Global().Get("process").Type() == js.TypeObject && |
| 50 | + - strings.HasPrefix(js.Global().Get("process").Get("argv0").String(), "node") |
| 51 | + +// Patched to always use Fetch API for better WASM compatibility in Node.js |
| 52 | + +var jsFetchDisabled = false |
| 53 | + |
| 54 | + // RoundTrip implements the [RoundTripper] interface using the WHATWG Fetch API. |
| 55 | + func (t *Transport) RoundTrip(req *Request) (*Response, error) { |
| 56 | + '') |
| 57 | + ]; |
| 58 | + }); |
61 | 59 | nodejs = pkgs.nodejs_22; |
62 | 60 |
|
63 | 61 | # Treefmt config. |
|
86 | 84 |
|
87 | 85 | nativeBuildInputs = [ |
88 | 86 | pkgs.bash |
89 | | - go |
| 87 | + goWasm # Use patched Go for WASM build |
90 | 88 | nodejs |
91 | 89 | pkgs.yarn |
92 | 90 | pkgs.yarnConfigHook |
|
174 | 172 | echo " return bytes;" >> dist/sindri/wasm/wasm.mjs |
175 | 173 | echo "}" >> dist/sindri/wasm/wasm.mjs |
176 | 174 |
|
177 | | - # Copy the real Go wasm_exec.js runtime. |
178 | | - cp "${go}/share/go/lib/wasm/wasm_exec.js" dist/sindri/wasm/wasm_exec.js |
179 | | - cp "${go}/share/go/lib/wasm/wasm_exec.js" dist/sindri/wasm/wasm_exec.mjs |
| 175 | + # Copy the real Go wasm_exec.js runtime from the patched Go. |
| 176 | + cp "${goWasm}/share/go/lib/wasm/wasm_exec.js" dist/sindri/wasm/wasm_exec.js |
| 177 | + cp "${goWasm}/share/go/lib/wasm/wasm_exec.js" dist/sindri/wasm/wasm_exec.mjs |
180 | 178 |
|
181 | 179 | runHook postBuild |
182 | 180 | ''; |
|
0 commit comments