Skip to content

Instantly share code, notes, and snippets.

@kripken
Last active May 23, 2021 17:36
Show Gist options
  • Save kripken/3cd771d3ee05e7fbc4f7f1b251f8d95e to your computer and use it in GitHub Desktop.
Save kripken/3cd771d3ee05e7fbc4f7f1b251f8d95e to your computer and use it in GitHub Desktop.
Building binaryen with zig cc

Building binaryen with zig cc

  1. Add zigcc, zigc++ scripts because cmake doens't accept a compiler with spaces in the name like "zig cc".
  2. The zigcc/zigc++ scripts can also add a target for cross-compiling as shown here.
  3. Disable threads (perhaps cmake cross-compiling needs to be set up?).
  4. Use a static build (otherwise cmake emits a .so - again, do we need cmake cross-compiling here?).
  5. ninja stalls on the final links: it just hangs. To solve that, run ninja wasm-opt and so forth manually, as a specific build target works.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e3f3f87a4..bb2fc6607 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -94,21 +94,21 @@ function(binaryen_setup_rpath name)
endif()
set_target_properties(${name} PROPERTIES
BUILD_WITH_INSTALL_RPATH On
INSTALL_RPATH "${_install_rpath}"
${_install_name_dir})
endfunction()
# Options
-option(BUILD_STATIC_LIB "Build as a static library" OFF)
+option(BUILD_STATIC_LIB "Build as a static library" ON)
if(MSVC)
# We don't have dllexport declarations set up for windows yet.
set(BUILD_STATIC_LIB ON)
endif()
# For now, don't include full DWARF support in JS builds, for size.
if(NOT EMSCRIPTEN)
option(BUILD_LLVM_DWARF "Enable full DWARF support" ON)
if(BUILD_LLVM_DWARF)
@@ -201,23 +201,22 @@ if(MSVC)
add_link_flag("/STACK:8388608")
if(RUN_STATIC_ANALYZER)
add_definitions(/analyze)
endif()
else()
option(ENABLE_WERROR "Enable -Werror" ON)
- set(THREADS_PREFER_PTHREAD_FLAG ON)
- set(CMAKE_THREAD_PREFER_PTHREAD ON)
- find_package(Threads REQUIRED)
+ set(THREADS_PREFER_PTHREAD_FLAG OFF)
+ set(CMAKE_THREAD_PREFER_PTHREAD OFF)
add_cxx_flag("-std=c++${CXX_STANDARD}")
if(NOT EMSCRIPTEN)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
# wasm doesn't allow for x87 floating point math
add_compile_flag("-msse2")
add_compile_flag("-mfpmath=sse")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^armv[2-6]" AND NOT CMAKE_CXX_FLAGS MATCHES "-mfpu=")
add_compile_flag("-mfpu=vfpv3")
endif()
endif()
@@ -312,28 +311,23 @@ if(BUILD_LLVM_DWARF)
SET(binaryen_objs ${binaryen_objs} $<TARGET_OBJECTS:llvm_dwarf>)
endif()
# Sources.
file(GLOB binaryen_HEADERS src/*.h)
set(binaryen_SOURCES
src/binaryen-c.cpp
${binaryen_HEADERS}
)
-if(BUILD_STATIC_LIB)
message(STATUS "Building libbinaryen as statically linked library.")
add_library(binaryen STATIC ${binaryen_SOURCES} ${binaryen_objs})
add_definitions(-DBUILD_STATIC_LIBRARY)
-else()
- message(STATUS "Building libbinaryen as shared library.")
- add_library(binaryen SHARED ${binaryen_SOURCES} ${binaryen_objs})
-endif()
if(NOT (BUILD_STATIC_LIB AND BYN_INSTALL_TOOLS_ONLY))
install(TARGETS binaryen
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT BYN_INSTALL_TOOLS_ONLY)
install(FILES src/binaryen-c.h src/wasm-delegations.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
This file has been truncated, but you can view the full file.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment