Move to 4 flavor build and tests

This commit is contained in:
Nick Gerleman
2022-12-23 00:43:57 -08:00
parent 4f233df064
commit 3352385fb0
15 changed files with 174 additions and 181 deletions

View File

@@ -1,8 +0,0 @@
{
"presets": [
["@babel/preset-env", {"targets": "defaults"}]
],
"plugins": [
"@babel/plugin-transform-flow-strip-types"
]
}

17
javascript/.babelrc.js Normal file
View File

@@ -0,0 +1,17 @@
/**
* 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
*/
module.exports = {
"presets": [
["@babel/preset-env", {"targets": "defaults"}]
],
"plugins": [
"@babel/plugin-transform-flow-strip-types"
]
};

11
javascript/.gitignore vendored
View File

@@ -1,10 +1,3 @@
node_modules /build
*.gypi
!/final-flags.gypi
/dist /dist
/build/* /node_modules
/sources/yoga
npm-debug.log*

View File

@@ -1,15 +0,0 @@
syntax:glob
node_modules
*.gypi
!/final-flags.gypi
/dist
/build/*
!/build/Release
/build/Release/*
!/build/Release/nbind.js
/sources/yoga
npm-debug.log*

72
javascript/CMakeLists.txt Normal file
View File

@@ -0,0 +1,72 @@
# 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.
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)
project(yoga)
file(GLOB SOURCES
../yoga/*.cpp
../yoga/**/*.cpp
sources/*.cc)
include_directories(..)
set(CXX_STANDARD, 11)
set(EMCC_FLAGS
-flto
-fno-exceptions
-fno-rtti
-g0
-Os
"SHELL:-s STRICT=1")
add_compile_options(
${EMCC_FLAGS}
-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0
-std=c++11)
add_link_options(
${EMCC_FLAGS}
--closure 1
--memory-init-file 0
--no-entry
"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"
"SHELL:-s MALLOC='emmalloc'"
"SHELL:-s MODULARIZE=1"
"SHELL:-s TEXTDECODER=0")
link_libraries(embind)
add_library(yogaObjLib OBJECT ${SOURCES})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist)
add_executable(asmjs-sync $<TARGET_OBJECTS:yogaObjLib>)
target_link_options(asmjs-sync PUBLIC
"SHELL:-s WASM=0"
"SHELL:-s WASM_ASYNC_COMPILATION=0")
add_executable(asmjs-async $<TARGET_OBJECTS:yogaObjLib>)
target_link_options(asmjs-async PUBLIC
"SHELL:-s WASM=0"
"SHELL:-s WASM_ASYNC_COMPILATION=1")
add_executable(wasm-sync $<TARGET_OBJECTS:yogaObjLib>)
target_link_options(wasm-sync PUBLIC
"SHELL:-s WASM=1"
"SHELL:-s WASM_ASYNC_COMPILATION=0")
add_executable(wasm-async $<TARGET_OBJECTS:yogaObjLib>)
target_link_options(wasm-async PUBLIC
"SHELL:-s WASM=1"
"SHELL:-s WASM_ASYNC_COMPILATION=1")

View File

@@ -1,67 +0,0 @@
CXX=em++
SOURCES=\
sources/yoga/*.cpp \
sources/yoga/**/*.cpp \
sources/*.cc
CXXFLAGS=\
-Isources \
-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 \
-std=c++11 \
-g0 \
-Os \
-flto \
-fno-exceptions \
-fno-rtti \
EMCCFLAGS=\
--closure 1 \
--memory-init-file 0 \
--no-entry
EMCCOPTS=\
-s ALLOW_MEMORY_GROWTH=1 \
-s ASSERTIONS=0 \
-s DEFAULT_TO_CXX=1 \
-s DYNAMIC_EXECUTION=0 \
-s ENVIRONMENT="web,node" \
-s EXPORT_NAME="yoga" \
-s FETCH_SUPPORT_INDEXEDDB=0 \
-s FILESYSTEM=0 \
-s MALLOC="emmalloc" \
-s MODULARIZE=1 \
-s STRICT=1 \
-s TEXTDECODER=0 \
-s USE_ES6_IMPORT_META=0
LDLIBS=\
-lembind
all: clean dir asm wasm
asm:
$(CXX) $(SOURCES) \
$(INCLUDE) \
$(CXXFLAGS) \
$(EMCCFLAGS) \
$(LDLIBS) \
$(EMCCOPTS) \
-s WASM=0 \
-o dist/asm.js
wasm:
$(CXX) $(SOURCES) \
$(INCLUDE) \
$(CXXFLAGS) \
$(EMCCFLAGS) \
$(LDLIBS) \
$(EMCCOPTS) \
-s WASM=1 \
-o dist/wasm.js
clean:
rm -rf dist
dir:
mkdir -p dist

View File

@@ -8,7 +8,7 @@
*/ */
module.exports = { module.exports = {
setupFiles: ["./jest.setup.js"], setupFiles: ["./jest.setup.js", "./tests/tools.js"],
testRegex: '/tests/Facebook.Yoga/.*\\.js$', testRegex: '/tests/Facebook.Yoga/.*\\.js$',
watchman: false, watchman: false,
} }

View File

@@ -8,62 +8,13 @@
*/ */
module.exports = async () => { module.exports = async () => {
global.Yoga = process.env['WASM'] if (process.env['SYNC'] && process.env['WASM']) {
? await require("./dist/index.wasm").initialize() global.Yoga = require("./dist/sync.wasm");
: await require("./dist/index.asm").initialize(); } else if (process.env['SYNC']) {
global.Yoga = require("./dist/sync.asmjs");
global.getMeasureCounter = function(Yoga, cb, staticWidth, staticHeight) { } else if (process.env['WASM']) {
var counter = 0; global.Yoga = await require("./dist/index.wasm").load();
} else {
return { global.Yoga = await require("./dist/index.asmjs").load();
inc: function(width, widthMode, height, heightMode) { }
counter += 1;
return cb
? cb(width, widthMode, height, heightMode)
: {width: staticWidth, height: staticHeight};
},
get: function() {
return counter;
},
};
};
global.getMeasureCounterMax = function(Yoga) {
return getMeasureCounter(Yoga, function(
width,
widthMode,
height,
heightMode,
) {
var measuredWidth = widthMode === Yoga.MEASURE_MODE_UNDEFINED ? 10 : width;
var measuredHeight =
heightMode === Yoga.MEASURE_MODE_UNDEFINED ? 10 : height;
return {width: measuredWidth, height: measuredHeight};
});
};
global.getMeasureCounterMin = function(Yoga) {
return getMeasureCounter(Yoga, function(
width,
widthMode,
height,
heightMode,
) {
var measuredWidth =
widthMode === Yoga.MEASURE_MODE_UNDEFINED ||
(widthMode == Yoga.MEASURE_MODE_AT_MOST && width > 10)
? 10
: width;
var measuredHeight =
heightMode === Yoga.MEASURE_MODE_UNDEFINED ||
(heightMode == Yoga.MEASURE_MODE_AT_MOST && height > 10)
? 10
: height;
return {width: measuredWidth, height: measuredHeight};
});
};
} }

View File

@@ -11,19 +11,31 @@
".": { ".": {
"browser": "./dist/index.wasm.js", "browser": "./dist/index.wasm.js",
"node": "./dist/index.wasm.js", "node": "./dist/index.wasm.js",
"react-native": "./dist/index.asm.js", "react-native": "./dist/index.asmjs.js",
"default": "./dist/index.asm.js" "default": "./dist/index.asmjs.js"
},
"./sync": {
"browser": "./dist/sync.asmks.js",
"node": "./dist/sync.wasm.js",
"react-native": "./dist/sync.asmjs.js",
"default": "./dist/sync.asmjs.js"
} }
}, },
"files": [
"dist/**",
"sources/**"
],
"scripts": { "scripts": {
"is-monolithic": "test \"$(basename \"$(pwd)\")\" = javascript", "build": "yarn build:native && yarn build:js",
"copy-sources": "! npm -s run is-monolithic || (rsync -r --checksum --delete ../yoga/ sources/yoga/)", "build:native": "yarn build:project && cmake --build build",
"build": "npm run copy-sources && make && npm run build:js", "build:project": "which ninja && emcmake cmake -S . -B build -G Ninja || emcmake cmake -S . -B build",
"test": "yarn test:asm && yarn test:wasm", "build:js": "babel sources --source-maps --out-dir dist && flow-copy-source sources dist",
"test:asm": "jest", "test": "yarn test:asmjs && yarn test:asmjs-sync && yarn test:wasm && yarn test:wasm-sync",
"test:asmjs": "jest",
"test:asmjs-sync": "SYNC=1 jest",
"test:wasm": "WASM=1 jest", "test:wasm": "WASM=1 jest",
"benchmark": "npm run build && node tests/run-bench $(find tests/Benchmarks -name '*.js')", "test:wasm-sync": "WASM=1 SYNC=1 jest",
"build:js": "babel sources --source-maps --out-dir dist && flow-copy-source sources dist" "benchmark": "node tests/run-bench $(find tests/Benchmarks -name '*.js')"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.20.7", "@babel/cli": "^7.20.7",

View File

@@ -8,7 +8,6 @@
* @format * @format
*/ */
const CONSTANTS = require('./YGEnums'); const CONSTANTS = require('./YGEnums');
import type { import type {
Yoga$Edge, Yoga$Edge,
@@ -238,7 +237,7 @@ type Yoga = {
...typeof CONSTANTS, ...typeof CONSTANTS,
}; };
function wrapLib(lib: any): Yoga { module.exports = function wrapLib(lib: any): Yoga {
function patch(prototype, name, fn) { function patch(prototype, name, fn) {
let original = prototype[name]; let original = prototype[name];
@@ -378,7 +377,3 @@ function wrapLib(lib: any): Yoga {
...CONSTANTS, ...CONSTANTS,
}; };
}; };
module.exports = (libPromise: any) => ({
initialize: () => libPromise.then(wrapLib)
}: YogaConstructor);

View File

@@ -0,0 +1,21 @@
/**
* 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.
*
* @flow
* @format
*/
const wrapLib = require('./entry');
const loadYoga = require('./asmjs-async');
module.exports = {
load: () => {
return loadYoga().then(wrapLib);
}
}
export type * from './YGEnums.js';
export type * from './entry';

View File

@@ -8,10 +8,14 @@
* @format * @format
*/ */
const entry = require('./entry'); const wrapLib = require('./entry');
const yoga = require('./wasm'); const loadYoga = require('./wasm-async');
module.exports = entry(yoga()); module.exports = {
load: () => {
return loadYoga().then(wrapLib);
}
}
export type * from './YGEnums.js'; export type * from './YGEnums.js';
export type * from './entry'; export type * from './entry';

View File

@@ -0,0 +1,17 @@
/**
* 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.
*
* @flow
* @format
*/
const wrapLib = require('./entry');
const loadYoga = require('./asmjs-sync');
module.exports = wrapLib(loadYoga());
export type * from './YGEnums.js';
export type * from './entry';

View File

@@ -8,10 +8,10 @@
* @format * @format
*/ */
const entry = require('./entry'); const wrapLib = require('./entry');
const yoga = require('./asm'); const loadYoga = require('./wasm-sync');
module.exports = entry(yoga()); module.exports = wrapLib(loadYoga());
export type * from './YGEnums.js'; export type * from './YGEnums.js';
export type * from './entry'; export type * from './entry';

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env node
/** /**
* Copyright (c) Meta Platforms, Inc. and affiliates. * Copyright (c) Meta Platforms, Inc. and affiliates.
* *
@@ -21,12 +22,12 @@ let testFiles = process.argv.slice(2).map(file => {
let testResults = new Map(); let testResults = new Map();
for (let type of ['asm', 'wasm']) { for (let type of ['asmjs', 'wasm']) {
for (let file of testFiles) { for (let file of testFiles) {
vm.runInNewContext( vm.runInNewContext(
file, file,
Object.assign(Object.create(global), { Object.assign(Object.create(global), {
Yoga: require(type === 'asm' ? '../dist/index.asm' : '../dist/index.wasm'), Yoga: require(type === 'asmjs' ? '../dist/sync.asmjs' : '../dist/sync.wasm'),
YGBENCHMARK: function(name, fn) { YGBENCHMARK: function(name, fn) {
let testEntry = testResults.get(name); let testEntry = testResults.get(name);