Separate Emscripten build into a new target

This was clearly a better idea as it cleans up CMakeLists.txt and allows
us to add more functionality in the future that's specific to web.
This commit is contained in:
Arseny Kapoulkine 2021-11-21 19:57:53 -08:00
parent 239605b8fa
commit 2665ffcd5e
4 changed files with 63 additions and 28 deletions

View file

@ -101,4 +101,4 @@ jobs:
run: |
source emsdk/emsdk_env.sh
emcmake cmake . -DCMAKE_BUILD_TYPE=Release
make -j2 Luau.Repl.CLI
make -j2 Luau.Web

View file

@ -33,3 +33,26 @@ jobs:
with:
name: luau-${{matrix.os}}
path: Release\luau*.exe
web:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
repository: emscripten-core/emsdk
path: emsdk
- name: emsdk install
run: |
cd emsdk
./emsdk install latest
./emsdk activate latest
- name: make
run: |
source emsdk/emsdk_env.sh
emcmake cmake . -DLUAU_BUILD_WEB=ON -DCMAKE_BUILD_TYPE=Release
make -j2 Luau.Web
- uses: actions/upload-artifact@v2
with:
name: Luau.Web.js
path: Luau.Web.js

View file

@ -9,6 +9,7 @@ project(Luau LANGUAGES CXX)
option(LUAU_BUILD_CLI "Build CLI" ON)
option(LUAU_BUILD_TESTS "Build tests" ON)
option(LUAU_BUILD_WEB "Build Web module" OFF)
option(LUAU_WERROR "Warnings as errors" OFF)
add_library(Luau.Ast STATIC)
@ -18,26 +19,22 @@ add_library(Luau.VM STATIC)
if(LUAU_BUILD_CLI)
add_executable(Luau.Repl.CLI)
if(NOT EMSCRIPTEN)
add_executable(Luau.Analyze.CLI)
else()
# add -fexceptions for emscripten to allow exceptions to be caught in C++
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
endif()
add_executable(Luau.Analyze.CLI)
# This also adds target `name` on Linux/macOS and `name.exe` on Windows
set_target_properties(Luau.Repl.CLI PROPERTIES OUTPUT_NAME luau)
if(NOT EMSCRIPTEN)
set_target_properties(Luau.Analyze.CLI PROPERTIES OUTPUT_NAME luau-analyze)
endif()
set_target_properties(Luau.Analyze.CLI PROPERTIES OUTPUT_NAME luau-analyze)
endif()
if(LUAU_BUILD_TESTS AND NOT EMSCRIPTEN)
if(LUAU_BUILD_TESTS)
add_executable(Luau.UnitTest)
add_executable(Luau.Conformance)
endif()
if(LUAU_BUILD_WEB)
add_executable(Luau.Web)
endif()
include(Sources.cmake)
target_compile_features(Luau.Ast PUBLIC cxx_std_17)
@ -72,16 +69,18 @@ if(LUAU_WERROR)
endif()
endif()
if(LUAU_BUILD_WEB)
# add -fexceptions for emscripten to allow exceptions to be caught in C++
list(APPEND LUAU_OPTIONS -fexceptions)
endif()
target_compile_options(Luau.Ast PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.Analysis PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.VM PRIVATE ${LUAU_OPTIONS})
if(LUAU_BUILD_CLI)
target_compile_options(Luau.Repl.CLI PRIVATE ${LUAU_OPTIONS})
if(NOT EMSCRIPTEN)
target_compile_options(Luau.Analyze.CLI PRIVATE ${LUAU_OPTIONS})
endif()
target_compile_options(Luau.Analyze.CLI PRIVATE ${LUAU_OPTIONS})
target_include_directories(Luau.Repl.CLI PRIVATE extern)
target_link_libraries(Luau.Repl.CLI PRIVATE Luau.Compiler Luau.VM)
@ -93,20 +92,10 @@ if(LUAU_BUILD_CLI)
endif()
endif()
if(NOT EMSCRIPTEN)
target_link_libraries(Luau.Analyze.CLI PRIVATE Luau.Analysis)
endif()
if(EMSCRIPTEN)
# declare exported functions to emscripten
target_link_options(Luau.Repl.CLI PRIVATE -sEXPORTED_FUNCTIONS=['_executeScript'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap'] -fexceptions)
# custom output directory for wasm + js file
set_target_properties(Luau.Repl.CLI PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/assets/luau)
endif()
target_link_libraries(Luau.Analyze.CLI PRIVATE Luau.Analysis)
endif()
if(LUAU_BUILD_TESTS AND NOT EMSCRIPTEN)
if(LUAU_BUILD_TESTS)
target_compile_options(Luau.UnitTest PRIVATE ${LUAU_OPTIONS})
target_include_directories(Luau.UnitTest PRIVATE extern)
target_link_libraries(Luau.UnitTest PRIVATE Luau.Analysis Luau.Compiler)
@ -115,3 +104,16 @@ if(LUAU_BUILD_TESTS AND NOT EMSCRIPTEN)
target_include_directories(Luau.Conformance PRIVATE extern)
target_link_libraries(Luau.Conformance PRIVATE Luau.Analysis Luau.Compiler Luau.VM)
endif()
if(LUAU_BUILD_WEB)
target_compile_options(Luau.Web PRIVATE ${LUAU_OPTIONS})
target_include_directories(Luau.Web PRIVATE extern)
target_link_libraries(Luau.Web PRIVATE Luau.Compiler Luau.VM)
# declare exported functions to emscripten
target_link_options(Luau.Web PRIVATE -sEXPORTED_FUNCTIONS=['_executeScript'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap'] -fexceptions)
target_link_options(Luau.Web PRIVATE -sSINGLE_FILE=1)
# custom output directory for wasm + js file
# set_target_properties(Luau.Repl.CLI PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/assets/luau)
endif()

View file

@ -224,3 +224,13 @@ if(TARGET Luau.Conformance)
tests/Conformance.test.cpp
tests/main.cpp)
endif()
if(TARGET Luau.Web)
# Luau.Web Sources
target_sources(Luau.Web PRIVATE
CLI/FileUtils.h
CLI/FileUtils.cpp
CLI/Profiler.h
CLI/Profiler.cpp
CLI/Repl.cpp)
endif()