Separate Node and Web Binaries (#1325)
Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1325 Fixes https://github.com/facebook/yoga/issues/1321 Reviewed By: cortinico Differential Revision: D47368830 fbshipit-source-id: 570a45ad7fd182ef82e6edda4037ae2f6faa0c75
This commit is contained in:
committed by
Nick Gerleman
parent
edf91b245d
commit
6628873c2a
@@ -37,13 +37,13 @@ add_link_options(
|
|||||||
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
|
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
|
||||||
"SHELL:-s ASSERTIONS=0"
|
"SHELL:-s ASSERTIONS=0"
|
||||||
"SHELL:-s DYNAMIC_EXECUTION=0"
|
"SHELL:-s DYNAMIC_EXECUTION=0"
|
||||||
"SHELL:-s ENVIRONMENT='web,node'"
|
|
||||||
"SHELL:-s EXPORT_NAME='loadYoga'"
|
"SHELL:-s EXPORT_NAME='loadYoga'"
|
||||||
"SHELL:-s FETCH_SUPPORT_INDEXEDDB=0"
|
"SHELL:-s FETCH_SUPPORT_INDEXEDDB=0"
|
||||||
"SHELL:-s FILESYSTEM=0"
|
"SHELL:-s FILESYSTEM=0"
|
||||||
"SHELL:-s MALLOC='emmalloc'"
|
"SHELL:-s MALLOC='emmalloc'"
|
||||||
"SHELL:-s MODULARIZE=1"
|
"SHELL:-s MODULARIZE=1"
|
||||||
"SHELL:-s TEXTDECODER=0")
|
"SHELL:-s TEXTDECODER=0"
|
||||||
|
"SHELL:-s SINGLE_FILE=1")
|
||||||
|
|
||||||
link_libraries(embind)
|
link_libraries(embind)
|
||||||
|
|
||||||
@@ -51,24 +51,62 @@ add_library(yogaObjLib OBJECT ${SOURCES})
|
|||||||
|
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/binaries)
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/binaries)
|
||||||
|
|
||||||
|
add_executable(asmjs-sync-node $<TARGET_OBJECTS:yogaObjLib>)
|
||||||
|
target_link_options(asmjs-sync-node PUBLIC
|
||||||
|
"SHELL:-s ENVIRONMENT='node'"
|
||||||
|
"SHELL:-s WASM=0"
|
||||||
|
"SHELL:-s WASM_ASYNC_COMPILATION=0")
|
||||||
|
|
||||||
|
add_executable(asmjs-async-node $<TARGET_OBJECTS:yogaObjLib>)
|
||||||
|
target_link_options(asmjs-async-node PUBLIC
|
||||||
|
"SHELL:-s ENVIRONMENT='node'"
|
||||||
|
"SHELL:-s WASM=0"
|
||||||
|
"SHELL:-s WASM_ASYNC_COMPILATION=1")
|
||||||
|
|
||||||
|
add_executable(asmjs-sync-web $<TARGET_OBJECTS:yogaObjLib>)
|
||||||
|
target_link_options(asmjs-sync-web PUBLIC
|
||||||
|
"SHELL:-s ENVIRONMENT='web'"
|
||||||
|
"SHELL:-s WASM=0"
|
||||||
|
"SHELL:-s WASM_ASYNC_COMPILATION=0")
|
||||||
|
|
||||||
|
add_executable(asmjs-async-web $<TARGET_OBJECTS:yogaObjLib>)
|
||||||
|
target_link_options(asmjs-async-web PUBLIC
|
||||||
|
"SHELL:-s ENVIRONMENT='web'"
|
||||||
|
"SHELL:-s WASM=0"
|
||||||
|
"SHELL:-s WASM_ASYNC_COMPILATION=1")
|
||||||
|
|
||||||
add_executable(asmjs-sync $<TARGET_OBJECTS:yogaObjLib>)
|
add_executable(asmjs-sync $<TARGET_OBJECTS:yogaObjLib>)
|
||||||
target_link_options(asmjs-sync PUBLIC
|
target_link_options(asmjs-sync PUBLIC
|
||||||
|
"SHELL:-s ENVIRONMENT='web,node'"
|
||||||
"SHELL:-s WASM=0"
|
"SHELL:-s WASM=0"
|
||||||
"SHELL:-s WASM_ASYNC_COMPILATION=0")
|
"SHELL:-s WASM_ASYNC_COMPILATION=0")
|
||||||
|
|
||||||
add_executable(asmjs-async $<TARGET_OBJECTS:yogaObjLib>)
|
add_executable(asmjs-async $<TARGET_OBJECTS:yogaObjLib>)
|
||||||
target_link_options(asmjs-async PUBLIC
|
target_link_options(asmjs-async PUBLIC
|
||||||
|
"SHELL:-s ENVIRONMENT='web,node'"
|
||||||
"SHELL:-s WASM=0"
|
"SHELL:-s WASM=0"
|
||||||
"SHELL:-s WASM_ASYNC_COMPILATION=1")
|
"SHELL:-s WASM_ASYNC_COMPILATION=1")
|
||||||
|
|
||||||
add_executable(wasm-sync $<TARGET_OBJECTS:yogaObjLib>)
|
add_executable(wasm-sync-node $<TARGET_OBJECTS:yogaObjLib>)
|
||||||
target_link_options(wasm-sync PUBLIC
|
target_link_options(wasm-sync-node PUBLIC
|
||||||
|
"SHELL:-s ENVIRONMENT='node'"
|
||||||
"SHELL:-s WASM=1"
|
"SHELL:-s WASM=1"
|
||||||
"SHELL:-s SINGLE_FILE=1"
|
|
||||||
"SHELL:-s WASM_ASYNC_COMPILATION=0")
|
"SHELL:-s WASM_ASYNC_COMPILATION=0")
|
||||||
|
|
||||||
add_executable(wasm-async $<TARGET_OBJECTS:yogaObjLib>)
|
add_executable(wasm-async-node $<TARGET_OBJECTS:yogaObjLib>)
|
||||||
target_link_options(wasm-async PUBLIC
|
target_link_options(wasm-async-node PUBLIC
|
||||||
|
"SHELL:-s ENVIRONMENT='node'"
|
||||||
|
"SHELL:-s WASM=1"
|
||||||
|
"SHELL:-s WASM_ASYNC_COMPILATION=1")
|
||||||
|
|
||||||
|
add_executable(wasm-sync-web $<TARGET_OBJECTS:yogaObjLib>)
|
||||||
|
target_link_options(wasm-sync-web PUBLIC
|
||||||
|
"SHELL:-s ENVIRONMENT='web'"
|
||||||
|
"SHELL:-s WASM=1"
|
||||||
|
"SHELL:-s WASM_ASYNC_COMPILATION=0")
|
||||||
|
|
||||||
|
add_executable(wasm-async-web $<TARGET_OBJECTS:yogaObjLib>)
|
||||||
|
target_link_options(wasm-async-web PUBLIC
|
||||||
|
"SHELL:-s ENVIRONMENT='web'"
|
||||||
"SHELL:-s WASM=1"
|
"SHELL:-s WASM=1"
|
||||||
"SHELL:-s SINGLE_FILE=1"
|
|
||||||
"SHELL:-s WASM_ASYNC_COMPILATION=1")
|
"SHELL:-s WASM_ASYNC_COMPILATION=1")
|
||||||
|
@@ -45,37 +45,35 @@ function defineFlavor(flavor: string, env: NodeJS.ProcessEnv) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
defineFlavor('asmjs-async', {WASM: '0', SYNC: '0'});
|
defineFlavor('asmjs-async-node', {WASM: '0', SYNC: '0'});
|
||||||
defineFlavor('asmjs-sync', {WASM: '0', SYNC: '1'});
|
defineFlavor('asmjs-sync-node', {WASM: '0', SYNC: '1'});
|
||||||
defineFlavor('wasm-async', {WASM: '1', SYNC: '0'});
|
defineFlavor('asmjs-async-web', {WASM: '0', SYNC: '0'});
|
||||||
defineFlavor('wasm-sync', {WASM: '1', SYNC: '1'});
|
defineFlavor('asmjs-sync-web', {WASM: '0', 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('build', series(emcmakeGenerateTask(), 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(
|
task(
|
||||||
'test',
|
'test',
|
||||||
series(
|
series(
|
||||||
emcmakeGenerateTask(),
|
emcmakeGenerateTask(),
|
||||||
series('cmake-build:asmjs-async', 'jest:asmjs-async'),
|
series('cmake-build:asmjs-async-node', 'jest:asmjs-async-node'),
|
||||||
series('cmake-build:asmjs-sync', 'jest:asmjs-sync'),
|
series('cmake-build:asmjs-sync-node', 'jest:asmjs-sync-node'),
|
||||||
series('cmake-build:wasm-async', 'jest:wasm-async'),
|
series('cmake-build:wasm-async-node', 'jest:wasm-async-node'),
|
||||||
series('cmake-build:wasm-sync', 'jest:wasm-sync'),
|
series('cmake-build:wasm-sync-node', 'jest:wasm-sync-node'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
task(
|
task(
|
||||||
'benchmark',
|
'benchmark',
|
||||||
series(emcmakeGenerateTask(), 'cmake-build:sync', runBenchTask()),
|
series(
|
||||||
|
emcmakeGenerateTask(),
|
||||||
|
cmakeBuildTask({targets: ['asmjs-sync-node', 'wasm-sync-node']}),
|
||||||
|
runBenchTask(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
task(
|
task(
|
||||||
|
@@ -11,19 +11,35 @@
|
|||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"browser": "./src/entrypoint/wasm-async.ts",
|
"browser": "./src/entrypoint/wasm-async-web.ts",
|
||||||
"node": "./src/entrypoint/wasm-async.ts",
|
"node": "./src/entrypoint/wasm-async-node.ts",
|
||||||
"default": "./src/entrypoint/asmjs-async.ts"
|
"default": "./src/entrypoint/asmjs-async-web.ts"
|
||||||
},
|
},
|
||||||
"./sync": {
|
"./sync": {
|
||||||
"browser": "./src/entrypoint/asmjs-sync.ts",
|
"browser": "./src/entrypoint/asmjs-sync-web.ts",
|
||||||
"node": "./src/entrypoint/wasm-sync.ts",
|
"node": "./src/entrypoint/wasm-sync-node.ts",
|
||||||
"default": "./src/entrypoint/asmjs-sync.ts"
|
"default": "./src/entrypoint/asmjs-sync-web.ts"
|
||||||
},
|
},
|
||||||
"./asmjs-async": "./src/entrypoint/asmjs-async.ts",
|
"./asmjs-async": {
|
||||||
"./asmjs-sync": "./src/entrypoint/asmjs-sync.ts",
|
"browser": "./src/entrypoint/asmjs-async-web.ts",
|
||||||
"./wasm-async": "./src/entrypoint/wasm-async.ts",
|
"node": "./src/entrypoint/asmjs-async-node.ts",
|
||||||
"./wasm-sync": "./src/entrypoint/wasm-sync.ts"
|
"default": "./src/entrypoint/asmjs-async-web.ts"
|
||||||
|
},
|
||||||
|
"./asmjs-sync": {
|
||||||
|
"browser": "./src/entrypoint/asmjs-sync-web.ts",
|
||||||
|
"node": "./src/entrypoint/asmjs-sync-node.ts",
|
||||||
|
"default": "./src/entrypoint/asmjs-sync-web.ts"
|
||||||
|
},
|
||||||
|
"./wasm-async": {
|
||||||
|
"browser": "./src/entrypoint/wasm-async-web.ts",
|
||||||
|
"node": "./src/entrypoint/wasm-async-node.ts",
|
||||||
|
"default": "./src/entrypoint/wasm-async-web.ts"
|
||||||
|
},
|
||||||
|
"./wasm-sync": {
|
||||||
|
"browser": "./src/entrypoint/wasm-sync-web.ts",
|
||||||
|
"node": "./src/entrypoint/wasm-sync-node.ts",
|
||||||
|
"default": "./src/entrypoint/wasm-async-web.ts"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"binaries/**",
|
"binaries/**",
|
||||||
@@ -36,11 +52,7 @@
|
|||||||
"lint": "just lint",
|
"lint": "just lint",
|
||||||
"lint:fix": "just lint --fix",
|
"lint:fix": "just lint --fix",
|
||||||
"prepack": "just prepack",
|
"prepack": "just prepack",
|
||||||
"test": "just test",
|
"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"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.20.7",
|
"@babel/cli": "^7.20.7",
|
||||||
|
26
javascript/src/entrypoint/asmjs-async-node.ts
Normal file
26
javascript/src/entrypoint/asmjs-async-node.ts
Normal file
@@ -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/asmjs-async-node');
|
||||||
|
|
||||||
|
export async function loadYoga(): Promise<Yoga> {
|
||||||
|
return wrapAssembly(await loadAssembly());
|
||||||
|
}
|
@@ -19,7 +19,7 @@ export type {
|
|||||||
Yoga,
|
Yoga,
|
||||||
} from '../wrapAssembly';
|
} from '../wrapAssembly';
|
||||||
|
|
||||||
const loadAssembly = require('../../binaries/wasm-async');
|
const loadAssembly = require('../../binaries/asmjs-async-web');
|
||||||
|
|
||||||
export async function loadYoga(): Promise<Yoga> {
|
export async function loadYoga(): Promise<Yoga> {
|
||||||
return wrapAssembly(await loadAssembly());
|
return wrapAssembly(await loadAssembly());
|
23
javascript/src/entrypoint/asmjs-sync-node.ts
Normal file
23
javascript/src/entrypoint/asmjs-sync-node.ts
Normal file
@@ -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/asmjs-sync-node');
|
||||||
|
const Yoga = wrapAssembly(loadAssembly());
|
||||||
|
export default Yoga;
|
@@ -18,6 +18,6 @@ export type {
|
|||||||
Yoga,
|
Yoga,
|
||||||
} from '../wrapAssembly';
|
} from '../wrapAssembly';
|
||||||
|
|
||||||
const loadAssembly = require('../../binaries/wasm-sync');
|
const loadAssembly = require('../../binaries/asmjs-sync-web');
|
||||||
const Yoga = wrapAssembly(loadAssembly());
|
const Yoga = wrapAssembly(loadAssembly());
|
||||||
export default Yoga;
|
export default Yoga;
|
26
javascript/src/entrypoint/wasm-async-node.ts
Normal file
26
javascript/src/entrypoint/wasm-async-node.ts
Normal file
@@ -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<Yoga> {
|
||||||
|
return wrapAssembly(await loadAssembly());
|
||||||
|
}
|
@@ -19,7 +19,7 @@ export type {
|
|||||||
Yoga,
|
Yoga,
|
||||||
} from '../wrapAssembly';
|
} from '../wrapAssembly';
|
||||||
|
|
||||||
const loadAssembly = require('../../binaries/asmjs-async');
|
const loadAssembly = require('../../binaries/wasm-async-web');
|
||||||
|
|
||||||
export async function loadYoga(): Promise<Yoga> {
|
export async function loadYoga(): Promise<Yoga> {
|
||||||
return wrapAssembly(await loadAssembly());
|
return wrapAssembly(await loadAssembly());
|
23
javascript/src/entrypoint/wasm-sync-node.ts
Normal file
23
javascript/src/entrypoint/wasm-sync-node.ts
Normal file
@@ -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;
|
@@ -18,6 +18,6 @@ export type {
|
|||||||
Yoga,
|
Yoga,
|
||||||
} from '../wrapAssembly';
|
} from '../wrapAssembly';
|
||||||
|
|
||||||
const loadAssembly = require('../../binaries/asmjs-sync');
|
const loadAssembly = require('../../binaries/wasm-sync-web');
|
||||||
const Yoga = wrapAssembly(loadAssembly());
|
const Yoga = wrapAssembly(loadAssembly());
|
||||||
export default Yoga;
|
export default Yoga;
|
Reference in New Issue
Block a user