Skip to content

Commit

Permalink
chore(driver): debug/release
Browse files Browse the repository at this point in the history
fixes #27
  • Loading branch information
atty303 committed May 15, 2024
1 parent 1dca8f7 commit 9215762
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE $<TARGET_FILE:zlib>)
target_include_directories(${PROJECT_NAME} PRIVATE $<TARGET_PROPERTY:zlib,INCLUDE_DIRECTORIES>)

set(DRIVER_LINK_FLAGS "
-flto -s MODULARIZE -s ASYNCIFY -s ENVIRONMENT=web,worker -s ALLOW_MEMORY_GROWTH\
-flto -s MODULARIZE -s ASYNCIFY -s ENVIRONMENT=web -s ALLOW_MEMORY_GROWTH\
-s EXPORTED_FUNCTIONS=[_malloc,_init,_start,_on_frame,_on_key_down,_on_key_up,_on_char,_on_download_page_result] -s EXPORTED_RUNTIME_METHODS=cwrap,ccall,FS,PATH,ERRNO_CODES\
")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand Down
2 changes: 2 additions & 0 deletions packages/driver/src/js/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Driver {
private resizeObserver: ResizeObserver | undefined;

constructor(
readonly build: "debug" | "release",
readonly assetPrefix: string,
readonly hostCallbacks: HostCallbacks,
) {}
Expand All @@ -30,6 +31,7 @@ export class Driver {
this.worker = new WorkerObject();
this.driverWorker = Comlink.wrap<DriverWorker>(this.worker);
return this.driverWorker.start(
this.build,
this.assetPrefix,
fileSystemConfig,
Comlink.proxy(async (key: string) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/driver/src/js/worker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as zenfs from "@zenfs/core";
import { Zip } from "@zenfs/zip";
import * as Comlink from "comlink";
// @ts-ignore
import { default as Module } from "../../dist/driver-release.mjs";
import type { FilesystemConfig } from "./driver.ts";
import type { UIState } from "./event.ts";
import { NodeEmscriptenFS, SimpleAsyncFS, SimpleAsyncStore } from "./fs";
Expand Down Expand Up @@ -66,6 +64,7 @@ export class DriverWorker {
private isRunning = true;

async start(
build: "debug" | "release",
assetPrefix: string,
fileSystemConfig: FilesystemConfig,
getCallback: (key: string) => Promise<Uint8Array | undefined>,
Expand Down Expand Up @@ -95,6 +94,8 @@ export class DriverWorker {
openUrl,
};

// @ts-ignore
const { default: Module } = await import(`../../dist/driver-${build}.mjs`);
const module = await Module({
print: console.log,
printErr: console.warn,
Expand Down
3 changes: 3 additions & 0 deletions packages/driver/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ export default defineConfig({
define: {
__ASSET_PREFIX__: JSON.stringify("https://pob-web-asset.atty303.ninja/versions"),
},
worker: {
format: "es",
},
});
2 changes: 1 addition & 1 deletion packages/web/src/PobWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function PobWindow(props: {
useEffect(() => {
log.debug(tag.pob, "loading version", props.version);

const _driver = new Driver(`${__ASSET_PREFIX__}/v${props.version}`, {
const _driver = new Driver("release", `${__ASSET_PREFIX__}/v${props.version}`, {
onError: (message) => {
throw new Error(message);
},
Expand Down
18 changes: 4 additions & 14 deletions packages/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,15 @@ export default defineConfig({
},
},
build: {
rollupOptions: {
output: {
assetFileNames: (assetInfo) => {
const noHash = [
// These files are loaded by the driver, and their names are hardcoded
"driver.wasm",
];
if (noHash.some((_) => assetInfo.name?.includes(_))) {
return "assets/[name][extname]";
}
return "assets/[name]-[hash][extname]";
},
},
},
chunkSizeWarningLimit: 1024,
},
define: {
APP_VERSION: JSON.stringify(process.env.npm_package_version),
__ASSET_PREFIX__: JSON.stringify("https://pob-web-asset.atty303.ninja/versions"),
},
worker: {
format: "es",
},
plugins: [
react(),
babel({
Expand Down

0 comments on commit 9215762

Please sign in to comment.