Skip to content

Commit

Permalink
feat: move wasm files to separate dir
Browse files Browse the repository at this point in the history
  • Loading branch information
x1unix committed Jan 9, 2024
1 parent 85f59d5 commit 0e868eb
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WASM_API_VER ?= $(shell cat ./cmd/wasm/api-version.txt)
define build_wasm_worker
@echo ":: Building WebAssembly worker '$(1)' ..."
GOOS=js GOARCH=wasm $(GO) build -buildvcs=false -ldflags "-s -w" -trimpath \
$(2) -o $(PUBLIC_DIR)/$(1)@$(WASM_API_VER).wasm ./cmd/wasm/$(1)
$(2) -o $(PUBLIC_DIR)/wasm/$(1)@$(WASM_API_VER).wasm ./cmd/wasm/$(1)
endef

define check_tool
Expand Down Expand Up @@ -59,7 +59,7 @@ build-ui:

.PHONY: wasm_exec.js
wasm_exec.js:
@cp "$(GOROOT)/misc/wasm/wasm_exec.js" $(PUBLIC_DIR)
@cp "$(GOROOT)/misc/wasm/wasm_exec.js" $(PUBLIC_DIR)/wasm/

.PHONY:build-webworker
analyzer.wasm:
Expand Down
4 changes: 2 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ ENV APP_GTAG_ID=''
COPY data ./data
COPY --from=ui-build /tmp/web/build ./public
COPY --from=build /tmp/playground/server .
COPY --from=build /tmp/playground/*.wasm ./public
COPY --from=build /tmp/playground/wasm_exec.js ./public
COPY --from=build /tmp/playground/*.wasm ./public/wasm/
COPY --from=build /tmp/playground/wasm_exec.js ./public/wasm/wasm_exec.js
EXPOSE 8000
ENTRYPOINT /opt/playground/server \
-f='/opt/playground/data/packages.json' \
Expand Down
4 changes: 2 additions & 2 deletions build/release.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ ENV APP_GTAG_ID=''
COPY data ./data
COPY web/build ./public
COPY --from=build /tmp/playground/server .
COPY --from=build /tmp/playground/*.wasm ./public
COPY --from=build /tmp/playground/wasm_exec.js ./public
COPY --from=build /tmp/playground/*.wasm ./public/wasm/
COPY --from=build /tmp/playground/wasm_exec.js ./public/wasm/wasm_exec.js
EXPOSE 8000
ENTRYPOINT /opt/playground/server \
-f='/opt/playground/data/packages.json' \
Expand Down
2 changes: 1 addition & 1 deletion web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
</div>
</div>
</div>
<script src="/wasm_exec.js"></script>
<script src="/wasm/wasm_exec.js"></script>
<% if (process.env.NODE_ENV === 'production') { %>
{{ if .GoogleTagID }}
<script async src="https://www.googletagmanager.com/gtag/js?id={{.GoogleTagID}}"></script>
Expand Down
2 changes: 1 addition & 1 deletion web/public/.gitignore → web/public/wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
wasm_exec.js
*.wasm
*.wasm
2 changes: 1 addition & 1 deletion web/src/service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ registerRoute(
);

// Cache WebAssembly and Go assets
const goWasmAssetsRegExp = new RegExp('^/(wasm_exec.js|go-repl.wasm|worker.wasm)$');
const goWasmAssetsRegExp = new RegExp('^/wasm/(.*)(.js|.wasm)$', 'i');
const DAY_IN_SECONDS = 24 * 60 * 60;
registerRoute(
({ url }) => url.origin === self.location.origin && goWasmAssetsRegExp.test(url.pathname),
Expand Down
2 changes: 1 addition & 1 deletion web/src/services/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export { default } from "./singleton";
export * from "./models";
export * from "./client";
export * from "./interface";
export * from "./utils";
export * from "./resources";
export * from "./provider";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {
REACT_APP_WASM_API_VER: wasmApiVersion = 'v1',
REACT_APP_WASM_BASE_URL: wasmBaseUrl = '',
REACT_APP_WASM_BASE_URL: wasmBaseUrl = '/wasm',
} = process.env;

/**
Expand All @@ -9,3 +9,8 @@ const {
* @param name
*/
export const getWasmUrl = name => `${wasmBaseUrl}/${name}@${wasmApiVersion}.wasm`;

/**
* URL for Go Wasm executor
*/
export const wasmExecUrl = `${wasmBaseUrl}/wasm_exec.js`;
2 changes: 1 addition & 1 deletion web/src/services/gorepl/worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { BrowserFSBinding } from "~/lib/gowasm/bindings/browserfs";
import { PackageDBBinding } from "~/lib/gowasm/bindings/packagedb";
import { Worker, WorkerBinding } from "~/lib/gowasm/bindings/worker";

import { getWasmUrl } from "~/services/api/utils";
import { getWasmUrl } from "~/services/api/resources";
import { wrapResponseWithProgress } from "~/utils/http";
import { FileSystemWrapper } from "~/services/go/fs";
import ProcessStub from "~/services/go/process";
Expand Down
4 changes: 2 additions & 2 deletions web/src/workers/analyzer.worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { instantiateStreaming } from "~/lib/go/common";
import { getWasmUrl } from "~/services/api/utils";
import { getWasmUrl, wasmExecUrl } from "~/services/api/resources";

declare const self: DedicatedWorkerGlobalScope;
export default {} as typeof Worker & { new (): Worker };
Expand All @@ -9,7 +9,7 @@ const FN_EXIT = 'exit';
const TYPE_ANALYZE = 'ANALYZE';
const TYPE_EXIT = 'EXIT';

self.importScripts('/wasm_exec.js');
self.importScripts(wasmExecUrl);

function wrapModule(module) {
const wrapped = {
Expand Down
3 changes: 2 additions & 1 deletion web/src/workers/repl.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import {
GoReplWorker,
startGoWorker, WorkerConfig,
} from "~/services/gorepl/worker";
import { wasmExecUrl } from "~/services/api/resources";

declare const self: DedicatedWorkerGlobalScope;
export default {} as typeof Worker & { new (): Worker };

self.importScripts('/wasm_exec.js');
self.importScripts(wasmExecUrl);

let worker: GoReplWorker|null = null;
const rpcClient = new Client(globalThis, {
Expand Down

0 comments on commit 0e868eb

Please sign in to comment.