diff --git a/javascript/CMakeLists.txt b/javascript/CMakeLists.txt index 3feeb54839..c17eaf5894 100644 --- a/javascript/CMakeLists.txt +++ b/javascript/CMakeLists.txt @@ -37,7 +37,6 @@ add_link_options( "SHELL:-s ALLOW_MEMORY_GROWTH=1" "SHELL:-s ASSERTIONS=0" "SHELL:-s DYNAMIC_EXECUTION=0" - "SHELL:-s ENVIRONMENT='web,node'" "SHELL:-s EXPORT_NAME='loadYoga'" "SHELL:-s FETCH_SUPPORT_INDEXEDDB=0" "SHELL:-s FILESYSTEM=0" @@ -53,22 +52,40 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/binaries) add_executable(asmjs-sync $) target_link_options(asmjs-sync PUBLIC + "SHELL:-s ENVIRONMENT='web,node'" "SHELL:-s WASM=0" "SHELL:-s WASM_ASYNC_COMPILATION=0") add_executable(asmjs-async $) target_link_options(asmjs-async PUBLIC + "SHELL:-s ENVIRONMENT='web,node'" "SHELL:-s WASM=0" "SHELL:-s WASM_ASYNC_COMPILATION=1") -add_executable(wasm-sync $) -target_link_options(wasm-sync PUBLIC +add_executable(wasm-sync-node $) +target_link_options(wasm-sync-node PUBLIC + "SHELL:-s ENVIRONMENT='node'" + "SHELL:-s WASM=1" + "SHELL:-s SINGLE_FILE=1" + "SHELL:-s WASM_ASYNC_COMPILATION=0") + +add_executable(wasm-async-node $) +target_link_options(wasm-async-node PUBLIC + "SHELL:-s ENVIRONMENT='node'" + "SHELL:-s WASM=1" + "SHELL:-s SINGLE_FILE=1" + "SHELL:-s WASM_ASYNC_COMPILATION=1") + +add_executable(wasm-sync-web $) +target_link_options(wasm-sync-web PUBLIC + "SHELL:-s ENVIRONMENT='web'" "SHELL:-s WASM=1" "SHELL:-s SINGLE_FILE=1" "SHELL:-s WASM_ASYNC_COMPILATION=0") -add_executable(wasm-async $) -target_link_options(wasm-async PUBLIC +add_executable(wasm-async-web $) +target_link_options(wasm-async-web PUBLIC + "SHELL:-s ENVIRONMENT='web'" "SHELL:-s WASM=1" "SHELL:-s SINGLE_FILE=1" "SHELL:-s WASM_ASYNC_COMPILATION=1") diff --git a/javascript/just.config.ts b/javascript/just.config.ts index 742b3da80d..acdcc34de6 100644 --- a/javascript/just.config.ts +++ b/javascript/just.config.ts @@ -47,20 +47,12 @@ function defineFlavor(flavor: string, env: NodeJS.ProcessEnv) { defineFlavor('asmjs-async', {WASM: '0', SYNC: '0'}); defineFlavor('asmjs-sync', {WASM: '0', SYNC: '1'}); -defineFlavor('wasm-async', {WASM: '1', SYNC: '0'}); -defineFlavor('wasm-sync', {WASM: '1', SYNC: '1'}); +defineFlavor('wasm-async-node', {WASM: '1', SYNC: '0'}); +defineFlavor('wasm-sync-node', {WASM: '1', SYNC: '1'}); +defineFlavor('wasm-async-web', {WASM: '1', SYNC: '0'}); +defineFlavor('wasm-sync-web', {WASM: '1', SYNC: '1'}); -task('cmake-build:all', cmakeBuildTask()); -task( - 'cmake-build:async', - cmakeBuildTask({targets: ['asmjs-async', 'wasm-async']}), -); -task( - 'cmake-build:sync', - cmakeBuildTask({targets: ['asmjs-sync', 'wasm-sync']}), -); - -task('build', series(emcmakeGenerateTask(), 'cmake-build:all')); +task('build', series(emcmakeGenerateTask(), cmakeBuildTask())); task( 'test', @@ -68,14 +60,18 @@ task( emcmakeGenerateTask(), series('cmake-build:asmjs-async', 'jest:asmjs-async'), series('cmake-build:asmjs-sync', 'jest:asmjs-sync'), - series('cmake-build:wasm-async', 'jest:wasm-async'), - series('cmake-build:wasm-sync', 'jest:wasm-sync'), + series('cmake-build:wasm-async-node', 'jest:wasm-async-node'), + series('cmake-build:wasm-sync-node', 'jest:wasm-sync-node'), ), ); task( 'benchmark', - series(emcmakeGenerateTask(), 'cmake-build:sync', runBenchTask()), + series( + emcmakeGenerateTask(), + cmakeBuildTask({targets: ['asmjs-sync', 'wasm-sync-node']}), + runBenchTask(), + ), ); task( diff --git a/javascript/package.json b/javascript/package.json index 8428083f88..2169faadd0 100644 --- a/javascript/package.json +++ b/javascript/package.json @@ -11,19 +11,25 @@ }, "exports": { ".": { - "browser": "./src/entrypoint/wasm-async.ts", - "node": "./src/entrypoint/wasm-async.ts", + "browser": "./src/entrypoint/wasm-async-web.ts", + "node": "./src/entrypoint/wasm-async-node.ts", "default": "./src/entrypoint/asmjs-async.ts" }, "./sync": { "browser": "./src/entrypoint/asmjs-sync.ts", - "node": "./src/entrypoint/wasm-sync.ts", + "node": "./src/entrypoint/wasm-sync-node.ts", "default": "./src/entrypoint/asmjs-sync.ts" }, "./asmjs-async": "./src/entrypoint/asmjs-async.ts", "./asmjs-sync": "./src/entrypoint/asmjs-sync.ts", - "./wasm-async": "./src/entrypoint/wasm-async.ts", - "./wasm-sync": "./src/entrypoint/wasm-sync.ts" + "./wasm-async": { + "browser": "./src/entrypoint/wasm-async-web.ts", + "node": "./src/entrypoint/wasm-async-node.ts" + }, + "./wasm-sync": { + "browser": "./src/entrypoint/wasm-sync-web.ts", + "node": "./src/entrypoint/wasm-sync-node.ts" + } }, "files": [ "binaries/**", @@ -36,11 +42,7 @@ "lint": "just lint", "lint:fix": "just lint --fix", "prepack": "just prepack", - "test": "just test", - "test:asmjs-async": "just test:asmjs-async", - "test:asmjs-sync": "just test:asmjs-sync", - "test:wasm-async": "just test:wasm-async", - "test:wasm-sync": "just test:wasm-sync" + "test": "just test" }, "devDependencies": { "@babel/cli": "^7.20.7", diff --git a/javascript/src/entrypoint/wasm-async-node.ts b/javascript/src/entrypoint/wasm-async-node.ts new file mode 100644 index 0000000000..8dea482ef6 --- /dev/null +++ b/javascript/src/entrypoint/wasm-async-node.ts @@ -0,0 +1,26 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import wrapAssembly from '../wrapAssembly'; +import type {Yoga} from '../wrapAssembly'; + +export * from '../generated/YGEnums'; +export type { + Config, + DirtiedFunction, + MeasureFunction, + Node, + Yoga, +} from '../wrapAssembly'; + +const loadAssembly = require('../../binaries/wasm-async-node'); + +export async function loadYoga(): Promise { + return wrapAssembly(await loadAssembly()); +} diff --git a/javascript/src/entrypoint/wasm-async.ts b/javascript/src/entrypoint/wasm-async-web.ts similarity index 89% rename from javascript/src/entrypoint/wasm-async.ts rename to javascript/src/entrypoint/wasm-async-web.ts index 752f759da1..092c7d86ee 100644 --- a/javascript/src/entrypoint/wasm-async.ts +++ b/javascript/src/entrypoint/wasm-async-web.ts @@ -19,7 +19,7 @@ export type { Yoga, } from '../wrapAssembly'; -const loadAssembly = require('../../binaries/wasm-async'); +const loadAssembly = require('../../binaries/wasm-async-web'); export async function loadYoga(): Promise { return wrapAssembly(await loadAssembly()); diff --git a/javascript/src/entrypoint/wasm-sync-node.ts b/javascript/src/entrypoint/wasm-sync-node.ts new file mode 100644 index 0000000000..f9f208d3f0 --- /dev/null +++ b/javascript/src/entrypoint/wasm-sync-node.ts @@ -0,0 +1,23 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import wrapAssembly from '../wrapAssembly'; + +export * from '../generated/YGEnums'; +export type { + Config, + DirtiedFunction, + MeasureFunction, + Node, + Yoga, +} from '../wrapAssembly'; + +const loadAssembly = require('../../binaries/wasm-sync-node'); +const Yoga = wrapAssembly(loadAssembly()); +export default Yoga; diff --git a/javascript/src/entrypoint/wasm-sync.ts b/javascript/src/entrypoint/wasm-sync-web.ts similarity index 88% rename from javascript/src/entrypoint/wasm-sync.ts rename to javascript/src/entrypoint/wasm-sync-web.ts index ff9bf7026f..da1a53aa1f 100644 --- a/javascript/src/entrypoint/wasm-sync.ts +++ b/javascript/src/entrypoint/wasm-sync-web.ts @@ -18,6 +18,6 @@ export type { Yoga, } from '../wrapAssembly'; -const loadAssembly = require('../../binaries/wasm-sync'); +const loadAssembly = require('../../binaries/wasm-sync-web'); const Yoga = wrapAssembly(loadAssembly()); export default Yoga;