Compare commits
5 Commits
NickGerlem
...
cramt/wasm
Author | SHA1 | Date | |
---|---|---|---|
|
1721ba112c | ||
|
3aa594c1f9 | ||
|
c2ae39167e | ||
|
49ee855f99 | ||
|
b12e0a2a15 |
23
.github/actions/clang-format/action.yml
vendored
23
.github/actions/clang-format/action.yml
vendored
@@ -1,23 +0,0 @@
|
|||||||
name: Clang Format
|
|
||||||
inputs:
|
|
||||||
directory:
|
|
||||||
description: Directory to Lint
|
|
||||||
required: true
|
|
||||||
version:
|
|
||||||
description: LLVM version to use # Should be kept roughly in sync with arcanist
|
|
||||||
required: false
|
|
||||||
default: 18
|
|
||||||
|
|
||||||
runs:
|
|
||||||
using: "composite"
|
|
||||||
steps:
|
|
||||||
- name: Install
|
|
||||||
shell: bash
|
|
||||||
run: sudo apt-get install -y clang-format-${{ inputs.version }}
|
|
||||||
|
|
||||||
- name: clang-format
|
|
||||||
working-directory: ${{ inputs.directory }}
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
BASHOPTS: extglob:nullglob
|
|
||||||
run: clang-format-${{ inputs.version }} --dry-run --Werror **/*.{h,hh,hpp,c,cpp,cc,m,mm}
|
|
12
.github/workflows/validate-cpp.yml
vendored
12
.github/workflows/validate-cpp.yml
vendored
@@ -97,15 +97,3 @@ jobs:
|
|||||||
cmake -S . -B build -G Ninja -D CMAKE_BUILD_TYPE=Release
|
cmake -S . -B build -G Ninja -D CMAKE_BUILD_TYPE=Release
|
||||||
cmake --build build
|
cmake --build build
|
||||||
working-directory: capture
|
working-directory: capture
|
||||||
|
|
||||||
clang-format:
|
|
||||||
name: Format
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: clang-format
|
|
||||||
uses: ./.github/actions/clang-format
|
|
||||||
with:
|
|
||||||
directory: yoga
|
|
||||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
26
gradlew
vendored
26
gradlew
vendored
@@ -15,6 +15,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
@@ -55,7 +57,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (3) This script is generated from the Groovy template
|
||||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
# within the Gradle project.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@@ -83,7 +85,8 @@ done
|
|||||||
# This is normally unused
|
# This is normally unused
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@@ -130,18 +133,21 @@ location of your Java installation."
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
@@ -149,7 +155,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
@@ -198,11 +204,11 @@ fi
|
|||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
# Collect all arguments for the java command:
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
# and any embedded shellness will be escaped.
|
||||||
# double quotes to make sure that they get re-expanded; and
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
22
gradlew.bat
vendored
22
gradlew.bat
vendored
@@ -13,6 +13,8 @@
|
|||||||
@rem See the License for the specific language governing permissions and
|
@rem See the License for the specific language governing permissions and
|
||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
|
|||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
@@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
|
@@ -1,4 +1,17 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.facebook.yoga"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0"
|
||||||
|
>
|
||||||
|
|
||||||
<application/>
|
<application/>
|
||||||
|
|
||||||
|
@@ -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