Skip to content

Commit

Permalink
Port walrus on windows
Browse files Browse the repository at this point in the history
Signed-off-by: Seonghyun Kim <[email protected]>
  • Loading branch information
ksh8281 authored and clover2123 committed Aug 28, 2023
1 parent 7b6602c commit a1fddb5
Show file tree
Hide file tree
Showing 14 changed files with 402 additions and 151 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,46 @@ jobs:
ninja -Cout/release
python3 ./tools/run-tests.py --engine="./out/release/walrus"
test-on-windows-x86-x64:
runs-on: windows-2022
strategy:
matrix:
arch: [x86, x64]
steps:
- name: Set git cllf config
run: |
git config --global core.autocrlf input
git config --global core.eol lf
- uses: actions/checkout@v3
with:
submodules: true
- uses: lukka/get-cmake@latest
- uses: GuillaumeFalourd/[email protected]
with:
sdk-version: 20348
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install msvc redist package
run: |
(new-object System.Net.WebClient).DownloadFile('https://github.com/abbodi1406/vcredist/releases/download/v0.73.0/VisualCppRedist_AIO_x86_x64.exe','VisualCppRedist_AIO_x86_x64.exe')
.\VisualCppRedist_AIO_x86_x64.exe /y
- uses: ilammy/[email protected]
with:
arch: ${{ matrix.arch }}
sdk: "10.0.20348.0"
- name: Build ${{ matrix.arch }} Release
run: |
CMake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=${{ matrix.arch }} -Bout/ -G Ninja -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=release
CMake --build out/ --config Release
- name: Run tests
run: |
python tools\run-tests.py --engine=%cd%\out\walrus.exe
shell: cmd
- if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 15

built-test-wasm-c-api:
runs-on: ubuntu-latest
steps:
Expand Down
62 changes: 0 additions & 62 deletions build/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,6 @@ SEPARATE_ARGUMENTS(CXXFLAGS_FROM_ENV)
SET (CFLAGS_FROM_ENV $ENV{CFLAGS})
SEPARATE_ARGUMENTS(CFLAGS_FROM_ENV)

SET (WALRUS_CXXFLAGS
${CXXFLAGS_FROM_ENV}
${WALRUS_CXXFLAGS}
-std=c++11
-fno-math-errno
-fdata-sections -ffunction-sections
-fno-omit-frame-pointer
-fvisibility=hidden
-Wno-unused-parameter
-Wno-type-limits -Wno-unused-result -Wno-unused-variable -Wno-invalid-offsetof
-Wno-deprecated-declarations
)

IF (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} -Wno-unused-but-set-variable -Wno-unused-but-set-parameter -Wno-mismatched-new-delete -Wno-attributes)
ELSEIF (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} -fno-fast-math -fno-unsafe-math-optimizations -fdenormal-fp-math=ieee -Wno-unsupported-floating-point-opt -Wno-parentheses-equality -Wno-dynamic-class-memaccess -Wno-deprecated-register -Wno-expansion-to-defined -Wno-return-type -Wno-overloaded-virtual -Wno-unused-private-field -Wno-deprecated-copy -Wno-atomic-alignment)
ELSE()
MESSAGE (FATAL_ERROR ${CMAKE_CXX_COMPILER_ID} " is Unsupported Compiler")
ENDIF()

SET (LDFLAGS_FROM_ENV $ENV{LDFLAGS})
SEPARATE_ARGUMENTS(LDFLAGS_FROM_ENV)

# WALRUS COMMON LDFLAGS
SET (WALRUS_LDFLAGS ${WALRUS_LDFLAGS} -fvisibility=hidden)

# bdwgc
IF (${WALRUS_MODE} STREQUAL "debug")
SET (WALRUS_DEFINITIONS_COMMON ${WALRUS_DEFINITIONS_COMMON} -DGC_DEBUG)
ENDIF()

IF (${WALRUS_OUTPUT} STREQUAL "shared_lib" AND ${WALRUS_HOST} STREQUAL "android")
SET (WALRUS_LDFLAGS ${WALRUS_LDFLAGS} -shared)
ENDIF()
Expand All @@ -68,28 +36,6 @@ ENDIF()
#######################################################
SET (WALRUS_LIBRARIES)
SET (WALRUS_INCDIRS)
FIND_PACKAGE (PkgConfig REQUIRED)

#######################################################
# FLAGS FOR $(MODE) : debug/release
#######################################################
# DEBUG FLAGS
SET (WALRUS_CXXFLAGS_DEBUG -O0 -g3 -Wall -Wextra -Werror ${WALRUS_CXXFLAGS_DEBUG})
SET (WALRUS_DEFINITIONS_DEBUG -D_GLIBCXX_DEBUG -DGC_DEBUG)

# RELEASE FLAGS
SET (WALRUS_CXXFLAGS_RELEASE -O2 -fno-stack-protector ${WALRUS_CXXFLAGS_RELEASE})
SET (WALRUS_DEFINITIONS_RELEASE -DNDEBUG)

# SHARED_LIB FLAGS
SET (WALRUS_CXXFLAGS_SHAREDLIB -fPIC)
SET (WALRUS_LDFLAGS_SHAREDLIB -ldl)

# STATIC_LIB FLAGS
SET (WALRUS_CXXFLAGS_STATICLIB -fPIC -DWALRUS_EXPORT=)

# SHELL FLAGS
SET (WALRUS_CXXFLAGS_SHELL -DWALRUS_EXPORT= -frtti -std=c++17)

#######################################################
# FLAGS FOR TEST
Expand All @@ -101,14 +47,6 @@ SET (WALRUS_DEFINITIONS_TEST -DWALRUS_ENABLE_TEST)
#######################################################
SET (PROFILER_FLAGS)

IF (WALRUS_PROFILE_BDWGC)
SET (PROFILER_FLAGS ${PROFILER_FLAGS} -DPROFILE_BDWGC)
ENDIF()

IF (WALRUS_MEM_STATS)
SET (PROFILER_FLAGS ${PROFILER_FLAGS} -DWALRUS_MEM_STATS)
ENDIF()

IF (WALRUS_VALGRIND)
SET (PROFILER_FLAGS ${PROFILER_FLAGS} -DWALRUS_VALGRIND)
ENDIF()
170 changes: 153 additions & 17 deletions build/target.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,118 @@
# default set of each flag
SET (WALRUS_CXXFLAGS -fno-rtti) # build walrus without rtti
SET (WALRUS_CXXFLAGS)
SET (WALRUS_CXXFLAGS_DEBUG)
SET (WALRUS_CXXFLAGS_RELEASE)
SET (WALRUS_LDFLAGS)
SET (WALRUS_DEFINITIONS)
SET (WALRUS_THIRDPARTY_CFLAGS)
SET (WALRUS_CXXFLAGS_SHAREDLIB)
SET (WALRUS_LDFLAGS_SHAREDLIB)
SET (WALRUS_CXXFLAGS_STATICLIB)
SET (WALRUS_CXXFLAGS_SHELL)

SET (WALRUS_BUILD_32BIT OFF)
SET (WALRUS_BUILD_64BIT OFF)
SET (WALRUS_BUILD_64BIT_LARGE OFF)

# clang-cl defines ${CMAKE_CXX_COMPILER_ID} "Clang" and ${CMAKE_CXX_COMPILER_FRONTEND_VARIANT} "MSVC"
SET (COMPILER_CLANG_CL OFF)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
IF (DEFINED CMAKE_CXX_COMPILER_FRONTEND_VARIANT)
IF ("${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")
SET (COMPILER_CLANG_CL ON)
ENDIF()
ENDIF()
ENDIF()

# Default options per compiler
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR ${COMPILER_CLANG_CL})
SET (WALRUS_CXXFLAGS /std:c++17 /fp:strict /Zc:__cplusplus /EHs /source-charset:utf-8 /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING /wd4244 /wd4267 /wd4805 /wd4018 /wd4172)
SET (WALRUS_CXXFLAGS_RELEASE /O2 /Oy-)
SET (WALRUS_THIRDPARTY_CFLAGS /D_CRT_SECURE_NO_WARNINGS /Oy- /wd4146 /EHs)
IF (${COMPILER_CLANG_CL})
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} /EHs -Wno-invalid-offsetof -Wno-inline-new-delete -fintegrated-cc1)
ENDIF()

IF (WALRUS_SMALL_CONFIG)
SET (WALRUS_CXXFLAGS_RELEASE ${WALRUS_CXXFLAGS_RELEASE} /Os)
ENDIF()
IF (WALRUS_DEBUG_INFO)
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} /DEBUG:FULL)
ENDIF()
SET (WALRUS_CXXFLAGS_SHAREDLIB)
SET (WALRUS_LDFLAGS_SHAREDLIB)
SET (WALRUS_CXXFLAGS_STATICLIB /DWALRUS_EXPORT)
SET (WALRUS_CXXFLAGS_SHELL /DWALRUS_EXPORT /std:c++17)
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET (WALRUS_CXXFLAGS
${WALRUS_CXXFLAGS}
-std=c++11 -g3
-fno-rtti
-fno-math-errno
-fdata-sections -ffunction-sections
-fno-omit-frame-pointer
-fvisibility=hidden
-frounding-math -fsignaling-nans
-Wno-unused-parameter
-Wno-type-limits -Wno-unused-result -Wno-unused-variable -Wno-invalid-offsetof
-Wno-unused-but-set-variable -Wno-unused-but-set-parameter
-Wno-deprecated-declarations -Wno-unused-function
)
IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9)
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} -Wno-attributes -Wno-class-memaccess -Wno-deprecated-copy -Wno-cast-function-type -Wno-stringop-truncation -Wno-pessimizing-move -Wno-mismatched-new-delete -Wno-overloaded-virtual -Wno-dangling-pointer)
endif()
SET (WALRUS_CXXFLAGS_DEBUG -O0 -Wall -Wextra -Werror)
SET (WALRUS_CXXFLAGS_RELEASE -O2 -fno-stack-protector -fno-omit-frame-pointer)
SET (WALRUS_THIRDPARTY_CFLAGS -w -g3 -fdata-sections -ffunction-sections -fno-omit-frame-pointer -fvisibility=hidden)
SET (WALRUS_DEFINITIONS ${WALRUS_DEFINITIONS} "WASM_API_EXTERN=__attribute__((visibility(\"default\")))")

IF (WALRUS_SMALL_CONFIG)
SET (WALRUS_CXXFLAGS_RELEASE ${WALRUS_CXXFLAGS_RELEASE} -Os)
ENDIF()
IF (WALRUS_DEBUG_INFO)
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} -g3)
ENDIF()
SET (WALRUS_CXXFLAGS_SHAREDLIB -fPIC)
SET (WALRUS_LDFLAGS_SHAREDLIB -ldl)
SET (WALRUS_CXXFLAGS_STATICLIB -fPIC -DWALRUS_EXPORT=)
SET (WALRUS_CXXFLAGS_SHELL -DWALRUS_EXPORT= -frtti -std=c++17)

ELSEIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # Clang and AppleClang
SET (WALRUS_CXXFLAGS
${WALRUS_CXXFLAGS}
-std=c++11 -g3
-fno-rtti
-fno-math-errno
-fdata-sections -ffunction-sections
-fno-omit-frame-pointer
-fvisibility=hidden
-fno-fast-math -fno-unsafe-math-optimizations -fdenormal-fp-math=ieee
-Wno-type-limits -Wno-unused-result -Wno-unused-variable -Wno-invalid-offsetof -Wno-unused-function
-Wno-deprecated-declarations -Wno-unsupported-floating-point-opt -Wno-parentheses-equality -Wno-dynamic-class-memaccess -Wno-deprecated-register
-Wno-expansion-to-defined -Wno-return-type -Wno-overloaded-virtual -Wno-unused-private-field -Wno-deprecated-copy -Wno-atomic-alignment
-Wno-ambiguous-reversed-operator -Wno-deprecated-enum-enum-conversion -Wno-deprecated-enum-float-conversion -Wno-braced-scalar-init -Wno-unused-parameter
)
SET (WALRUS_CXXFLAGS_DEBUG -O0 -Wall -Wextra -Werror)
SET (WALRUS_CXXFLAGS_RELEASE -O2 -fno-stack-protector -fno-omit-frame-pointer)
SET (WALRUS_THIRDPARTY_CFLAGS -w -g3 -fdata-sections -ffunction-sections -fno-omit-frame-pointer -fvisibility=hidden)
SET (WALRUS_DEFINITIONS ${WALRUS_DEFINITIONS} "WASM_API_EXTERN=__attribute__((visibility(\"default\")))")

IF (WALRUS_SMALL_CONFIG)
SET (WALRUS_CXXFLAGS_RELEASE ${WALRUS_CXXFLAGS_RELEASE} -Os)
ENDIF()
IF (WALRUS_DEBUG_INFO)
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} -g3)
ENDIF()
SET (WALRUS_CXXFLAGS_SHAREDLIB -fPIC)
SET (WALRUS_LDFLAGS_SHAREDLIB -ldl)
SET (WALRUS_CXXFLAGS_STATICLIB -fPIC -DWALRUS_EXPORT=)
SET (WALRUS_CXXFLAGS_SHELL -DWALRUS_EXPORT= -frtti -std=c++17)
ELSE()
MESSAGE (FATAL_ERROR ${CMAKE_CXX_COMPILER_ID} " is Unsupported Compiler")
ENDIF()

# Default options per host
IF (${WALRUS_HOST} STREQUAL "linux")
FIND_PACKAGE (PkgConfig REQUIRED)
# default set of LDFLAGS
SET (WALRUS_LDFLAGS -lpthread -lrt -Wl,--gc-sections)
IF ((${WALRUS_ARCH} STREQUAL "x64") OR (${WALRUS_ARCH} STREQUAL "x86_64"))
Expand All @@ -22,14 +126,18 @@ IF (${WALRUS_HOST} STREQUAL "linux")
SET (WALRUS_BUILD_32BIT ON)
ELSEIF (${WALRUS_ARCH} STREQUAL "aarch64")
SET (WALRUS_BUILD_64BIT ON)
ELSEIF (${WALRUS_ARCH} STREQUAL "riscv64")
SET (WALRUS_BUILD_64BIT ON)
ELSE()
MESSAGE (FATAL_ERROR ${WALRUS_ARCH} " is unsupported")
ENDIF()
ELSEIF (${WALRUS_HOST} STREQUAL "tizen_obs")
ELSEIF (${WALRUS_HOST} STREQUAL "tizen" OR ${WALRUS_HOST} STREQUAL "tizen_obs")
FIND_PACKAGE (PkgConfig REQUIRED)
# default set of LDFLAGS
SET (WALRUS_LDFLAGS -lpthread -lrt -Wl,--gc-sections)
SET (WALRUS_DEFINITIONS -DWALRUS_TIZEN)
IF ((${WALRUS_ARCH} STREQUAL "x64") OR (${WALRUS_ARCH} STREQUAL "x86_64"))
SET (WALRUS_BUILD_64BIT ON)
ELSEIF ((${WALRUS_ARCH} STREQUAL "x86") OR (${WALRUS_ARCH} STREQUAL "i686"))
SET (WALRUS_BUILD_32BIT ON)
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} -m32 -mfpmath=sse -msse -msse2)
Expand All @@ -41,32 +149,64 @@ ELSEIF (${WALRUS_HOST} STREQUAL "tizen_obs")
SET (WALRUS_CXXFLAGS_RELEASE -O2)
ELSEIF (${WALRUS_ARCH} STREQUAL "aarch64")
SET (WALRUS_BUILD_64BIT ON)
ELSEIF (${WALRUS_ARCH} STREQUAL "riscv64")
SET (WALRUS_BUILD_64BIT ON)
ELSE()
MESSAGE (FATAL_ERROR ${WALRUS_ARCH} " is unsupported")
ENDIF()
ELSEIF (${WALRUS_HOST} STREQUAL "android")
FIND_PACKAGE (PkgConfig REQUIRED)
SET (WALRUS_DEFINITIONS -DANDROID=1 -DWALRUS_ANDROID=1)
SET (WALRUS_THIRDPARTY_CFLAGS ${WALRUS_THIRDPARTY_CFLAGS} -mstackrealign)
SET (WALRUS_CXXFLAGS -mstackrealign)
# android + clang -O2 option causes crash (gc cannot scan stack correctly I guess)
SET (WALRUS_CXXFLAGS_RELEASE -Oz)
IF (${WALRUS_ARCH} STREQUAL "armeabi-v7a")
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} -mstackrealign)
IF (${WALRUS_ARCH} STREQUAL "arm")
SET (WALRUS_BUILD_32BIT ON)
SET (WALRUS_LDFLAGS -fPIE -pie -march=armv7-a -Wl,--fix-cortex-a8 -llog -Wl,--gc-sections)
ELSEIF ((${WALRUS_ARCH} STREQUAL "arm64-v8a") OR (${WALRUS_ARCH} STREQUAL "aarch64"))
SET (WALRUS_BUILD_64BIT_LARGE ON)
ELSEIF ((${WALRUS_ARCH} STREQUAL "arm64") OR (${WALRUS_ARCH} STREQUAL "aarch64"))
SET (WALRUS_BUILD_64BIT ON)
SET (WALRUS_LDFLAGS -fPIE -pie -llog -Wl,--gc-sections)
ELSEIF (${WALRUS_ARCH} STREQUAL "x86")
SET (WALRUS_BUILD_32BIT ON)
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} -m32 -mfpmath=sse -msse -msse2 -mstackrealign)
SET (WALRUS_LDFLAGS -fPIE -pie -llog -Wl,--gc-sections -m32)
ELSEIF (${WALRUS_ARCH} STREQUAL "x86_64")
SET (WALRUS_BUILD_64BIT_LARGE ON)
ELSEIF (${WALRUS_ARCH} STREQUAL "x86_64" OR ${WALRUS_ARCH} STREQUAL "x64")
SET (WALRUS_BUILD_64BIT ON)
SET (WALRUS_LDFLAGS -fPIE -pie -llog -Wl,--gc-sections)
# bdwgc android amd64 cannot support keeping back ptrs
SET (WALRUS_THIRDPARTY_CFLAGS ${WALRUS_THIRDPARTY_CFLAGS} -UKEEP_BACK_PTRS -USAVE_CALL_COUNT -UDBG_HDRS_ALL)
ENDIF()
ELSEIF (${WALRUS_HOST} STREQUAL "darwin" AND ${WALRUS_ARCH} STREQUAL "x64")
FIND_PACKAGE (PkgConfig REQUIRED)
SET (WALRUS_LDFLAGS -lpthread -Wl,-dead_strip)
SET (WALRUS_BUILD_64BIT_LARGE ON)
# bdwgc mac cannot support pthread_getattr_np
SET (WALRUS_THIRDPARTY_CFLAGS ${WALRUS_THIRDPARTY_CFLAGS} -UHAVE_PTHREAD_GETATTR_NP)
SET (WALRUS_BUILD_64BIT ON)
ELSEIF (${WALRUS_HOST} STREQUAL "windows")
# in windows, default stack limit is 1MB
# but expand stack to 8MB when building to exe for running test
IF (${WALRUS_OUTPUT} STREQUAL "shell")
# Default limit on windows is 1MB
# but we needs more stack to pass testcases
# and we needs more reserved space for process stackoverflow exception
# msvc process native exception catch on top of stack :(
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} /DSTACK_LIMIT_FROM_BASE=4194304)
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:16777216")
ELSE()
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} /DSTACK_LIMIT_FROM_BASE=524288)
ENDIF()

IF ((${WALRUS_ARCH} STREQUAL "x64") OR (${WALRUS_ARCH} STREQUAL "x86_64"))
SET (WALRUS_BUILD_64BIT ON)
ELSEIF ((${WALRUS_ARCH} STREQUAL "x86") OR (${WALRUS_ARCH} STREQUAL "i686"))
SET (WALRUS_BUILD_32BIT ON)
ELSEIF (${WALRUS_ARCH} STREQUAL "arm")
SET (WALRUS_BUILD_32BIT ON)
ELSEIF (${WALRUS_ARCH} STREQUAL "aarch64" OR (${WALRUS_ARCH} STREQUAL "arm64"))
SET (WALRUS_BUILD_64BIT ON)
ELSE()
MESSAGE (FATAL_ERROR ${WALRUS_ARCH} " is unsupported")
ENDIF()

ELSE()
MESSAGE (FATAL_ERROR ${WALRUS_HOST} " with " ${WALRUS_ARCH} " is unsupported")
ENDIF()
Expand All @@ -76,11 +216,7 @@ IF (WALRUS_BUILD_32BIT)
SET (WALRUS_DEFINITIONS ${WALRUS_DEFINITIONS} -DWALRUS_32=1)
ELSEIF (WALRUS_BUILD_64BIT)
# 64bit build
SET (WALRUS_DEFINITIONS ${WALRUS_DEFINITIONS} -DWALRUS_64=1 -DWALRUS_USE_32BIT_IN_64BIT)
SET (WALRUS_THIRDPARTY_CFLAGS ${WALRUS_THIRDPARTY_CFLAGS} -DWALRUS_USE_32BIT_IN_64BIT)
ELSEIF (WALRUS_BUILD_64BIT_LARGE)
# 64bit build(large)
SET (WALRUS_DEFINITIONS ${WALRUS_DEFINITIONS} -DWALRUS_64=1)
ELSE()
MESSAGE (FATAL_ERROR "unsupported mode")
ENDIF()
ENDIF()
Loading

0 comments on commit a1fddb5

Please sign in to comment.