Files
CWasm/build.bat

42 lines
1.2 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
set app_source_path=..\test_app.c
echo %1 | findstr /r "^[A-Za-z]:" >nul
if not "%1"=="" (
if %errorlevel% equ 0 (
set app_source_path=%1
) else (
set app_source_path=..\%1
)
)
set app_module_name=app.wasm
if not "%2"=="" (
set app_module_name=%2
)
if not exist build mkdir build
pushd build
rem TODO: Take the app.c file path as an argument?
echo [Compiling %app_source_path% to %app_module_name%...]
clang %app_source_path% -o "%app_module_name%" -I ".." -I "..\std" -std=gnu2x --target=wasm32-unknown-unknown -mbulk-memory -Wl,--no-entry,--export-dynamic,--allow-undefined,--export=__heap_base --no-standard-libraries --no-standard-includes
if %ERRORLEVEL% NEQ 0 (
echo [FAILED to build %app_module_name%!]
goto :build_end
) else (
echo [Done!]
)
XCOPY ".\%app_module_name%" "..\data\" /Y > NUL
rem Convert .wasm to .wat (the text format for WebAssembly) for debug inspection
set "app_module_wat_name=%app_module_name:.wasm=.wat%"
if "%app_module_wat_name%" == "%app_module_name%" (
set app_module_wat_name=%app_module_name%.wat
)
echo [Converting %app_module_name% to %app_module_wat_name%...]
wasm2wat "%app_module_name%" > "%app_module_wat_name%"
:build_end
popd