Skip to content

Commit

Permalink
Orca libC. This is a combination of 45 commits:
Browse files Browse the repository at this point in the history
* start of orca-libc
* adding intscan/floatscan, strtod/strtol
* add dummy crt to allow linking to orca-libc just by passing --sysroot=orca-libc
* adding scanf and stb_sprintf implementations
* added malloc
* added minimal wide char support for vfscanf
* adding abort
* Adding exit/_Exit/atexit
* testing replacement of libc-shim with orca-libc
* fix oc_bridge_exit def in core_api.json
* Pre-compile orca-libc and orca wasm sdk when building the runtime
* wip fileio
* first pass FILE interfaces implemented
* add fprintf/fscanf
* update libc notes
* disable clang-format for libc
* wip migrating to musl implementations of FILE functions
* first pass migrating to musl FILE functions
* samples build with new libc (win32 only)
* rework win32 sample build scripts to use --sysroot approach
* Adding --test support to orca runtime
* Specifying --test=path_to_wasm_module will run a special harness oc_on_test() that returns an exit code - 0 for success. The orca runtime will immediately exit after running the test.
* bugfix in win32 oc_io_raw_open_at: comparing wrong flags
* stdio libc fixes
  * expose feof and ferror as real functions so they can be used by client code
  * moved ofl_add.c into correct folder
  * fixed some fopen -> orca flags
* fseek() shim bugfix: translating between orca/libc whence flags
* Fix oc_bridge_io_wait_single_req to not error when buffer is null if operation does not require a buffer (e.g. OC_IO_SEEK)
* wip wasm stdio tests
* stdio wasm test: ferror() and clearerr()
* stdio wasm tests: test_jail()
* orca libc: putc/getc and more tests
  * test_eof
  * test_getputc
  * test_getsetpos
* orca libc: fgets/fputs and tests
* orca libc: wip fprintf/fscanf test
* update wasm test run.sh
* orca libc: fprintf/fscanf and tests
* update samples build.bat to not have --no-default-libraries
* ftell test
* libc stdio: rewind
* libc stdio: freopen
* libc stdio: setbuf and setvbuf
* add implementations for a few more printf variants
* replace stb sprintf with musl version
* orca libc: ungetc
* add std handles stdout, stderr, stdin
  * they print errors on any operations, but can be freopen-ed to be redirected to a file
* avoid crash on fclose() std handle
* orca libc: perror
* update macos sample build scripts

Co-authored-by: Reuben Dunnington <[email protected]>
Co-authored-by: Martin Fouilleul <[email protected]>
  • Loading branch information
rdunnington and martinfouilleul committed Mar 10, 2024
1 parent 3d90657 commit dac2644
Show file tree
Hide file tree
Showing 634 changed files with 29,131 additions and 3,411 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ build
*.app
*.dylib
*.a
*.o
*.d

Debug/*

Expand Down
17 changes: 6 additions & 11 deletions samples/breakout/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,22 @@ if exist "..\..\scripts\sample_build_check.py" (
echo If you have copied this script to your own project, you can delete this code.
)

set ORCA_DIR=..\..
set STDLIB_DIR=%ORCA_DIR%\src\libc-shim
set ORCA_DIR=../..
set STDLIB_DIR=%ORCA_DIR%/build/orca-libc

:: common flags to build wasm modules
set wasmFlags=--target=wasm32^
--no-standard-libraries ^
-mbulk-memory ^
-g -O2 ^
-D__ORCA__ ^
-Wl,--no-entry ^
-Wl,--export-dynamic ^
-isystem %STDLIB_DIR%\include ^
-I%ORCA_DIR%\src ^
-I%ORCA_DIR%\src\ext

:: build orca core as wasm module
clang %wasmFlags% -Wl,--relocatable -o .\liborca.a %ORCA_DIR%\src\orca.c %ORCA_DIR%\src\libc-shim\src\*.c
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
--sysroot %ORCA_DIR%/build/orca-libc ^
-I%ORCA_DIR%/src ^
-I%ORCA_DIR%/src/ext

:: build sample as wasm module and link it with the orca module
clang %wasmFlags% -L . -lorca -o module.wasm src/main.c
clang %wasmFlags% -L %ORCA_DIR%/build/bin -lorca_wasm -o module.wasm src/main.c
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%

:: create app directory and copy files into it
Expand Down
9 changes: 2 additions & 7 deletions samples/breakout/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,20 @@ else
fi

ORCA_DIR=../..
STDLIB_DIR=$ORCA_DIR/src/libc-shim

# common flags to build wasm modules
wasmFlags="--target=wasm32 \
--no-standard-libraries \
-mbulk-memory \
-g -O2 \
-D__ORCA__ \
-Wl,--no-entry \
-Wl,--export-dynamic \
-isystem $STDLIB_DIR/include \
--sysroot $ORCA_DIR/build/orca-libc \
-I $ORCA_DIR/src \
-I $ORCA_DIR/src/ext"

# build orca core as wasm module
clang $wasmFlags -Wl,--relocatable -o ./liborca.a $ORCA_DIR/src/orca.c $STDLIB_DIR/src/*.c

# build sample as wasm module and link it with the orca module
clang $wasmFlags -L . -lorca -o module.wasm src/main.c
clang $wasmFlags -L $ORCA_DIR/build/bin -lorca_wasm -o module.wasm src/main.c

# create app directory and copy files into it
orca bundle --orca-dir $ORCA_DIR --name Breakout --icon icon.png --resource-dir data module.wasm
17 changes: 6 additions & 11 deletions samples/clock/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,22 @@ if exist "..\..\scripts\sample_build_check.py" (
echo If you have copied this script to your own project, you can delete this code.
)

set ORCA_DIR=..\..
set STDLIB_DIR=%ORCA_DIR%\src\libc-shim
set ORCA_DIR=../..
set STDLIB_DIR=%ORCA_DIR%/build/orca-libc

:: common flags to build wasm modules
set wasmFlags=--target=wasm32^
--no-standard-libraries ^
-mbulk-memory ^
-g -O2 ^
-D__ORCA__ ^
-Wl,--no-entry ^
-Wl,--export-dynamic ^
-isystem %STDLIB_DIR%\include ^
-I%ORCA_DIR%\src ^
-I%ORCA_DIR%\src\ext

:: build orca core as wasm module
clang %wasmFlags% -Wl,--relocatable -o .\liborca.a %ORCA_DIR%\src\orca.c %ORCA_DIR%\src\libc-shim\src\*.c
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
--sysroot %ORCA_DIR%/build/orca-libc ^
-I%ORCA_DIR%/src ^
-I%ORCA_DIR%/src/ext

:: build sample as wasm module and link it with the orca module
clang %wasmFlags% -L . -lorca -o module.wasm src/main.c
clang %wasmFlags% -L %ORCA_DIR%/build/bin -lorca_wasm -o module.wasm src/main.c
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%

:: create app directory and copy files into it
Expand Down
18 changes: 9 additions & 9 deletions samples/fluid/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,23 @@ if exist "..\..\scripts\sample_build_check.py" (
echo If you have copied this script to your own project, you can delete this code.
)

set ORCA_DIR=..\..
set STDLIB_DIR=%ORCA_DIR%\src\libc-shim
set ORCA_DIR=../..
set STDLIB_DIR=%ORCA_DIR%/build/orca-libc

:: common flags to build wasm modules
set wasmFlags=--target=wasm32^
--no-standard-libraries ^
-mbulk-memory ^
-g -O2 ^
-D__ORCA__ ^
-Wl,--no-entry ^
-Wl,--export-dynamic ^
-isystem %STDLIB_DIR%\include ^
-I%ORCA_DIR%\src ^
-I%ORCA_DIR%\src\ext
--sysroot %ORCA_DIR%/build/orca-libc ^
-I%ORCA_DIR%/src ^
-I%ORCA_DIR%/src/ext

:: build orca core as wasm module
clang %wasmFlags% -Wl,--relocatable -o .\liborca.a %ORCA_DIR%\src\orca.c %ORCA_DIR%\src\libc-shim\src\*.c
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
rem clang %wasmFlags% -Wl,--relocatable -o .\liborca.a %ORCA_DIR%\src\orca.c %ORCA_DIR%\src\libc-shim\src\*.c
rem IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%

set shaders=src/shaders/advect.glsl^
src/shaders/blit_div_fragment.glsl^
Expand All @@ -50,8 +49,9 @@ call python ../../scripts/embed_text_files.py --prefix=glsl_ --output src/glsl_s
if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL!

:: build sample as wasm module and link it with the orca module
clang %wasmFlags% -L . -lorca -o .\module.wasm src\main.c
clang %wasmFlags% -L %ORCA_DIR%/build/bin -lorca_wasm -o module.wasm src/main.c
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%

:: create app directory and copy files into it
orca bundle --orca-dir %ORCA_DIR% --name Fluid --icon icon.png module.wasm

9 changes: 2 additions & 7 deletions samples/fluid/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,22 @@ else
fi

ORCA_DIR=../..
STDLIB_DIR=$ORCA_DIR/src/libc-shim

python3 ../../scripts/embed_text_files.py --prefix=glsl_ --output src/glsl_shaders.h src/shaders/*.glsl

# common flags to build wasm modules
wasmFlags="--target=wasm32 \
--no-standard-libraries \
-mbulk-memory \
-g -O2 \
-D__ORCA__ \
-Wl,--no-entry \
-Wl,--export-dynamic \
-isystem $STDLIB_DIR/include \
--sysroot $ORCA_DIR/build/orca-libc \
-I $ORCA_DIR/src \
-I $ORCA_DIR/src/ext"

# build orca core as wasm module
clang $wasmFlags -Wl,--relocatable -o ./liborca.a $ORCA_DIR/src/orca.c $STDLIB_DIR/src/*.c

# build sample as wasm module and link it with the orca module
clang $wasmFlags -L . -lorca -o module.wasm src/main.c
clang $wasmFlags -L $ORCA_DIR/build/bin -lorca_wasm -o module.wasm src/main.c

# create app directory and copy files into it
orca bundle --orca-dir $ORCA_DIR --name Fluid --icon icon.png module.wasm
18 changes: 7 additions & 11 deletions samples/triangle/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,23 @@ if exist "..\..\scripts\sample_build_check.py" (
echo If you have copied this script to your own project, you can delete this code.
)

set ORCA_DIR=..\..
set STDLIB_DIR=%ORCA_DIR%\src\libc-shim

set ORCA_DIR=../..
set STDLIB_DIR=%ORCA_DIR%/build/orca-libc

:: common flags to build wasm modules
set wasmFlags=--target=wasm32^
--no-standard-libraries ^
-mbulk-memory ^
-g -O2 ^
-D__ORCA__ ^
-Wl,--no-entry ^
-Wl,--export-dynamic ^
-isystem %STDLIB_DIR%\include ^
-I%ORCA_DIR%\src ^
-I%ORCA_DIR%\src\ext

:: build orca core as wasm module
clang %wasmFlags% -Wl,--relocatable -o .\liborca.a %ORCA_DIR%\src\orca.c %ORCA_DIR%\src\libc-shim\src\*.c
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
--sysroot %ORCA_DIR%/build/orca-libc ^
-I%ORCA_DIR%/src ^
-I%ORCA_DIR%/src/ext

:: build sample as wasm module and link it with the orca module
clang %wasmFlags% -L . -lorca -o module.wasm src/main.c
clang %wasmFlags% -L %ORCA_DIR%/build/bin -lorca_wasm -o module.wasm src/main.c
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%

:: create app directory and copy files into it
Expand Down
9 changes: 2 additions & 7 deletions samples/triangle/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,20 @@ else
fi

ORCA_DIR=../..
STDLIB_DIR=$ORCA_DIR/src/libc-shim

# common flags to build wasm modules
wasmFlags="--target=wasm32 \
--no-standard-libraries \
-mbulk-memory \
-g -O2 \
-D__ORCA__ \
-Wl,--no-entry \
-Wl,--export-dynamic \
-isystem $STDLIB_DIR/include \
--sysroot $ORCA_DIR/build/orca-libc \
-I $ORCA_DIR/src \
-I $ORCA_DIR/src/ext"

# build orca core as wasm module
clang $wasmFlags -Wl,--relocatable -o ./liborca.a $ORCA_DIR/src/orca.c $STDLIB_DIR/src/*.c

# build sample as wasm module and link it with the orca module
clang $wasmFlags -L . -lorca -o module.wasm src/main.c
clang $wasmFlags -L $ORCA_DIR/build/bin -lorca_wasm -o module.wasm src/main.c

# create app directory and copy files into it
orca bundle --orca-dir $ORCA_DIR --name Triangle module.wasm
17 changes: 6 additions & 11 deletions samples/ui/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,22 @@ if exist "..\..\scripts\sample_build_check.py" (
echo If you have copied this script to your own project, you can delete this code.
)

set ORCA_DIR=..\..
set STDLIB_DIR=%ORCA_DIR%\src\libc-shim
set ORCA_DIR=../..
set STDLIB_DIR=%ORCA_DIR%/build/orca-libc

:: common flags to build wasm modules
set wasmFlags=--target=wasm32^
--no-standard-libraries ^
-mbulk-memory ^
-g -O2 ^
-D__ORCA__ ^
-Wl,--no-entry ^
-Wl,--export-dynamic ^
-isystem %STDLIB_DIR%\include ^
-I%ORCA_DIR%\src ^
-I%ORCA_DIR%\src\ext

:: build orca core as wasm module
clang %wasmFlags% -Wl,--relocatable -o .\liborca.a %ORCA_DIR%\src\orca.c %ORCA_DIR%\src\libc-shim\src\*.c
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
--sysroot %ORCA_DIR%/build/orca-libc ^
-I%ORCA_DIR%/src ^
-I%ORCA_DIR%/src/ext

:: build sample as wasm module and link it with the orca module
clang %wasmFlags% -L . -lorca -o .\module.wasm src\main.c
clang %wasmFlags% -L %ORCA_DIR%/build/bin -lorca_wasm -o module.wasm src/main.c
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%

:: create app directory and copy files into it
Expand Down
9 changes: 2 additions & 7 deletions samples/ui/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,20 @@ else
fi

ORCA_DIR=../..
STDLIB_DIR=$ORCA_DIR/src/libc-shim

# common flags to build wasm modules
wasmFlags="--target=wasm32 \
--no-standard-libraries \
-mbulk-memory \
-g -O2 \
-D__ORCA__ \
-Wl,--no-entry \
-Wl,--export-dynamic \
-isystem $STDLIB_DIR/include \
--sysroot $ORCA_DIR/build/orca-libc \
-I $ORCA_DIR/src \
-I $ORCA_DIR/src/ext"

# build orca core as wasm module
clang $wasmFlags -Wl,--relocatable -o ./liborca.a $ORCA_DIR/src/orca.c $STDLIB_DIR/src/*.c

# build sample as wasm module and link it with the orca module
clang $wasmFlags -L . -lorca -o module.wasm src/main.c
clang $wasmFlags -L $ORCA_DIR/build/bin -lorca_wasm -o module.wasm src/main.c

# create app directory and copy files into it
orca bundle --orca-dir $ORCA_DIR --name UI --resource-dir data module.wasm
1 change: 1 addition & 0 deletions samples/ui/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
**************************************************************************/
#include "orca.h"
#include <math.h>
#include <stdio.h>

oc_vec2 frameSize = { 1200, 838 };

Expand Down
Loading

0 comments on commit dac2644

Please sign in to comment.