Skip to content

Embind port #7239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
yolo
  • Loading branch information
kripken committed Mar 29, 2024
commit 24d9c826b430767f10be975893c12f56e16580dd
30 changes: 27 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,9 @@ if(EMSCRIPTEN)
# On Node.js, make the tools immediately usable.
add_link_flag("-sNODERAWFS")
endif()
# in opt builds, LTO helps so much (>20%) it's worth slow compile times
add_nondebug_compile_flag("-flto")
endif()
# in opt builds, LTO helps so much (>20%) it's worth slow compile times
#add_nondebug_compile_flag("-flto")
endif()

# clang doesn't print colored diagnostics when invoked from Ninja
if(UNIX AND CMAKE_GENERATOR STREQUAL "Ninja")
Expand Down Expand Up @@ -539,6 +539,30 @@ if(EMSCRIPTEN)
target_link_libraries(binaryen_js debug "--profiling")
target_link_libraries(binaryen_js debug "-sASSERTIONS")
install(TARGETS binaryen_js DESTINATION ${CMAKE_INSTALL_BINDIR})

# binaryen.embind.js variant (WebAssembly)
add_executable(binaryen_embind_wasm
src/binaryen_embind.cpp
${binaryen_emscripten_SOURCES})
target_link_libraries(binaryen_embind_wasm wasm asmjs emscripten-optimizer passes ir cfg support analysis parser wasm)
target_link_libraries(binaryen_embind_wasm "-sFILESYSTEM")
target_link_libraries(binaryen_embind_wasm "-sEXPORT_NAME=Binaryen")
target_link_libraries(binaryen_embind_wasm "-sNODERAWFS=0")
# Do not error on the repeated NODERAWFS argument
target_link_libraries(binaryen_embind_wasm "-Wno-unused-command-line-argument")
# Emit a single file for convenience of people using binaryen.js as a library,
# so they only need to distribute a single file.
target_link_libraries(binaryen_embind_wasm "-sSINGLE_FILE")
target_link_libraries(binaryen_embind_wasm "-sEXPORT_ES6")
target_link_libraries(binaryen_embind_wasm "--bind")
target_link_libraries(binaryen_embind_wasm "-msign-ext")
target_link_libraries(binaryen_embind_wasm "-mbulk-memory")
#target_link_libraries(binaryen_embind_wasm optimized "--closure=1")
# TODO: Fix closure warnings! (#5062)
target_link_libraries(binaryen_embind_wasm optimized "-Wno-error=closure")
#target_link_libraries(binaryen_embind_wasm optimized "-flto")
target_link_libraries(binaryen_embind_wasm debug "--profiling")
install(TARGETS binaryen_embind_wasm DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

configure_file(scripts/binaryen-lit.in ${CMAKE_BINARY_DIR}/bin/binaryen-lit @ONLY)
26 changes: 26 additions & 0 deletions src/binaryen-embind.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024 WebAssembly Community Group participants
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

//==============================
// Binaryen Embind declarations
//==============================

#include <emscripten/bind.h>

#include "wasm.h"

using namespace wasm;