Compare commits
1 Commits
export-D70
...
cramt/wasm
Author | SHA1 | Date | |
---|---|---|---|
|
1721ba112c |
@@ -24,7 +24,7 @@ jobs:
|
|||||||
ORG_GRADLE_PROJECT_SIGNING_PWD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PWD }}
|
ORG_GRADLE_PROJECT_SIGNING_PWD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PWD }}
|
||||||
|
|
||||||
- name: Upload Build Artifacts
|
- name: Upload Build Artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: 'snapshot-artifacts'
|
name: 'snapshot-artifacts'
|
||||||
path: '~/.m2/repository/'
|
path: '~/.m2/repository/'
|
||||||
|
@@ -23,7 +23,7 @@ jobs:
|
|||||||
ORG_GRADLE_PROJECT_USE_SNAPSHOT: true
|
ORG_GRADLE_PROJECT_USE_SNAPSHOT: true
|
||||||
|
|
||||||
- name: Upload Build Artifacts
|
- name: Upload Build Artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: 'snapshot-artifacts'
|
name: 'snapshot-artifacts'
|
||||||
path: '~/.m2/repository/'
|
path: '~/.m2/repository/'
|
||||||
|
2
.github/workflows/validate-js.yml
vendored
2
.github/workflows/validate-js.yml
vendored
@@ -110,7 +110,7 @@ jobs:
|
|||||||
run: yarn pack --filename yoga-layout.tar.gz
|
run: yarn pack --filename yoga-layout.tar.gz
|
||||||
working-directory: javascript
|
working-directory: javascript
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: npm-package
|
name: npm-package
|
||||||
path: javascript/yoga-layout.tar.gz
|
path: javascript/yoga-layout.tar.gz
|
||||||
|
@@ -19,8 +19,8 @@ add_compile_options(
|
|||||||
# Enable warnings and warnings as errors
|
# Enable warnings and warnings as errors
|
||||||
/W4
|
/W4
|
||||||
/WX
|
/WX
|
||||||
# Enable RTTI
|
# Disable RTTI
|
||||||
$<$<COMPILE_LANGUAGE:CXX>:/GR>
|
$<$<COMPILE_LANGUAGE:CXX>:/GR->
|
||||||
# Use /O2 (Maximize Speed)
|
# Use /O2 (Maximize Speed)
|
||||||
$<$<CONFIG:RELEASE>:/O2>)
|
$<$<CONFIG:RELEASE>:/O2>)
|
||||||
|
|
||||||
@@ -34,8 +34,8 @@ add_compile_options(
|
|||||||
# Enable warnings and warnings as errors
|
# Enable warnings and warnings as errors
|
||||||
-Wall
|
-Wall
|
||||||
-Werror
|
-Werror
|
||||||
# Enable RTTI
|
# Disable RTTI
|
||||||
$<$<COMPILE_LANGUAGE:CXX>:-frtti>
|
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
|
||||||
# Use -O2 (prioritize speed)
|
# Use -O2 (prioritize speed)
|
||||||
$<$<CONFIG:RELEASE>:-O2>
|
$<$<CONFIG:RELEASE>:-O2>
|
||||||
# Enable separate sections per function/data item
|
# Enable separate sections per function/data item
|
||||||
|
@@ -29,6 +29,32 @@ set(COMPILE_OPTIONS
|
|||||||
|
|
||||||
add_compile_options(${COMPILE_OPTIONS})
|
add_compile_options(${COMPILE_OPTIONS})
|
||||||
|
|
||||||
|
link_libraries(embind)
|
||||||
|
|
||||||
|
add_library(yogaObjLib OBJECT ${SOURCES})
|
||||||
|
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/binaries)
|
||||||
|
|
||||||
|
add_link_options(
|
||||||
|
${COMPILE_OPTIONS}
|
||||||
|
"SHELL:--closure 1"
|
||||||
|
"SHELL:--memory-init-file 0"
|
||||||
|
"SHELL:--no-entry"
|
||||||
|
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
|
||||||
|
"SHELL:-s ASSERTIONS=0"
|
||||||
|
"SHELL:-s DYNAMIC_EXECUTION=0"
|
||||||
|
"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 EXPORT_ES6=1"
|
||||||
|
"SHELL:-s WASM=1"
|
||||||
|
"SHELL:-s TEXTDECODER=0"
|
||||||
|
"SHELL:-s ENVIRONMENT='web'")
|
||||||
|
|
||||||
|
add_executable(yoga-wasm-separate-esm $<TARGET_OBJECTS:yogaObjLib>)
|
||||||
|
|
||||||
add_link_options(
|
add_link_options(
|
||||||
${COMPILE_OPTIONS}
|
${COMPILE_OPTIONS}
|
||||||
"SHELL:--closure 1"
|
"SHELL:--closure 1"
|
||||||
@@ -45,15 +71,7 @@ add_link_options(
|
|||||||
"SHELL:-s EXPORT_ES6=1"
|
"SHELL:-s EXPORT_ES6=1"
|
||||||
"SHELL:-s WASM=1"
|
"SHELL:-s WASM=1"
|
||||||
"SHELL:-s TEXTDECODER=0"
|
"SHELL:-s TEXTDECODER=0"
|
||||||
# SINGLE_FILE=1 combined with ENVIRONMENT='web' creates code that works on
|
|
||||||
# both bundlders and Node.
|
|
||||||
"SHELL:-s SINGLE_FILE=1"
|
"SHELL:-s SINGLE_FILE=1"
|
||||||
"SHELL:-s ENVIRONMENT='web'")
|
"SHELL:-s ENVIRONMENT='web'")
|
||||||
|
|
||||||
link_libraries(embind)
|
|
||||||
|
|
||||||
add_library(yogaObjLib OBJECT ${SOURCES})
|
|
||||||
|
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/binaries)
|
|
||||||
|
|
||||||
add_executable(yoga-wasm-base64-esm $<TARGET_OBJECTS:yogaObjLib>)
|
add_executable(yoga-wasm-base64-esm $<TARGET_OBJECTS:yogaObjLib>)
|
||||||
|
@@ -7,13 +7,14 @@ See more at https://yogalayout.dev
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import {Yoga, Align} from 'yoga-layout';
|
import { Align, Yoga } from "yoga-layout";
|
||||||
|
|
||||||
const node = Yoga.Node.create();
|
const node = Yoga.Node.create();
|
||||||
node.setAlignContent(Align.Center);
|
node.setAlignContent(Align.Center);
|
||||||
```
|
```
|
||||||
|
|
||||||
Objects created by `Yoga.<>.create()` are not automatically garbage collected and should be freed once they are no longer in use.
|
Objects created by `Yoga.<>.create()` are not automatically garbage collected
|
||||||
|
and should be freed once they are no longer in use.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
// Free a config
|
// Free a config
|
||||||
@@ -30,11 +31,19 @@ node.free();
|
|||||||
|
|
||||||
`yoga-layout` requires a toolchain that supports ES Modules and top-level await.
|
`yoga-layout` requires a toolchain that supports ES Modules and top-level await.
|
||||||
|
|
||||||
If top-level-await is not supported, use the `yoga-layout/load` entry point instead. This requires to load yoga manually:
|
If top-level-await is not supported, use the `yoga-layout/load` entry point
|
||||||
|
instead. This requires to load yoga manually:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import {loadYoga, Align} from 'yoga-layout/load';
|
import { Align, loadYoga } from "yoga-layout/load";
|
||||||
|
|
||||||
const node = (await loadYoga).Node.create();
|
const node = (await loadYoga).Node.create();
|
||||||
node.setAlignContent(Align.Center);
|
node.setAlignContent(Align.Center);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also use `yoga-layout/loadSeparate`, which has the exactly same api as
|
||||||
|
`yoga-layout/load`, if you want the js and wasm in separate files, this can
|
||||||
|
useful in several scenarios such as avoiding
|
||||||
|
[unsafe-wasm-eval](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_webassembly_execution).
|
||||||
|
Do be aware that this option might not work out of the box with any and all
|
||||||
|
bundlers or frameworks
|
||||||
|
@@ -14,7 +14,8 @@
|
|||||||
"types": "./src/index.ts",
|
"types": "./src/index.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./src/index.ts",
|
".": "./src/index.ts",
|
||||||
"./load": "./src/load.ts"
|
"./load": "./src/load.ts",
|
||||||
|
"./loadSeparate": "./src/loadSeparate.ts"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist/binaries/**",
|
"dist/binaries/**",
|
||||||
|
25
javascript/src/loadSeparate.ts
Normal file
25
javascript/src/loadSeparate.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
// @ts-ignore untyped from Emscripten
|
||||||
|
import loadYogaImpl from '../binaries/yoga-wasm-separate-esm.js';
|
||||||
|
import wrapAssembly from './wrapAssembly.ts';
|
||||||
|
|
||||||
|
export type {
|
||||||
|
Config,
|
||||||
|
DirtiedFunction,
|
||||||
|
MeasureFunction,
|
||||||
|
Node,
|
||||||
|
Yoga,
|
||||||
|
} from './wrapAssembly.ts';
|
||||||
|
|
||||||
|
export async function loadYoga() {
|
||||||
|
return wrapAssembly(await loadYogaImpl());
|
||||||
|
}
|
||||||
|
export * from './generated/YGEnums.ts';
|
Reference in New Issue
Block a user