Skip to content

Commit 709e2f9

Browse files
committed
Renamed bindings and updated profiles
1 parent e8c9be6 commit 709e2f9

File tree

7 files changed

+50
-36
lines changed

7 files changed

+50
-36
lines changed

examples/cross_build/wasm/bindings/CMakeLists.txt

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,7 @@ add_executable(wasm_example main.cpp)
66

77
target_link_libraries(${PROJECT_NAME} PRIVATE Eigen3::Eigen)
88

9-
install(TARGETS wasm_example DESTINATION "."
10-
RUNTIME DESTINATION bin
11-
ARCHIVE DESTINATION lib
12-
LIBRARY DESTINATION lib
13-
)
14-
15-
# Required for Emscripten + embind
9+
# Set the executable suffix to .html in order to generate a html page by
10+
# Emscripten (there is no way of setting this from a user toolchain or
11+
# conanfile as it is later overridden by the Emscripten toolchain)
1612
set(CMAKE_EXECUTABLE_SUFFIX ".html")
17-
18-
set_target_properties(wasm_example PROPERTIES
19-
LINK_FLAGS
20-
"-sEXPORTED_FUNCTIONS=['_malloc','_free'] \
21-
-sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','getValue','setValue'] \
22-
-sENVIRONMENT=web \
23-
-sALLOW_MEMORY_GROWTH=1 \
24-
-sNO_EXIT_RUNTIME=1 \
25-
--shell-file ${CMAKE_SOURCE_DIR}/shell.html"
26-
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
from test.examples_tools import run
3+
4+
run("conan build . --build=missing --profile:host ../profiles/wasm32")
5+
6+
assert os.path.exists(os.path.join("build", "release-wasm", "wasm_example.html"))
7+
assert os.path.exists(os.path.join("build", "release-wasm", "wasm_example.js"))
8+
assert os.path.exists(os.path.join("build", "release-wasm", "wasm_example.wasm"))

examples/cross_build/wasm/bindings/conanfile.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,8 @@ class WasmExampleRecipe(ConanFile):
99
name = "wasm-example"
1010
version = "1.0"
1111
package_type = "application"
12-
13-
# Optional metadata
14-
license = "<Put the package license here>"
15-
author = "<Put your name here> <And your email here>"
16-
url = "<Package recipe repository url here, for issues about the package>"
17-
description = "<Description of exe package here>"
18-
topics = ("<Put some tag here>", "<here>", "<and here>")
19-
20-
# Binary configuration
2112
settings = "os", "compiler", "build_type", "arch"
2213

23-
# Sources are located in the same place as this recipe, copy them to the recipe
24-
exports_sources = "CMakeLists.txt", "src/*"
25-
2614
def layout(self):
2715
cmake_layout(self)
2816

@@ -33,13 +21,19 @@ def generate(self):
3321
deps = CMakeDeps(self)
3422
deps.generate()
3523
tc = CMakeToolchain(self)
24+
25+
tc.extra_exelinkflags.append(
26+
"-sEXPORTED_FUNCTIONS=['_malloc','_free'] \
27+
-sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','getValue','setValue'] \
28+
-sENVIRONMENT=web \
29+
-sALLOW_MEMORY_GROWTH=1 \
30+
-sNO_EXIT_RUNTIME=1 \
31+
--shell-file ${CMAKE_SOURCE_DIR}/shell.html"
32+
)
33+
3634
tc.generate()
3735

3836
def build(self):
3937
cmake = CMake(self)
4038
cmake.configure()
4139
cmake.build()
42-
43-
def package(self):
44-
cmake = CMake(self)
45-
cmake.install()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import platform
2+
from test.examples_tools import chdir, run
3+
4+
run("conan build . --build=missing --profile:host ../profiles/wasm32")
5+
run("conan build . --build=missing --profile:host ../profiles/wasm64")
6+
7+
if platform.system() == "Windows":
8+
with chdir("build"):
9+
run("generators\\conanbuild.bat && node --version && node release-wasm\\wasm-alloc.js")
10+
# Needs at least Node.js 24.0.0
11+
# run("generators\\conanbuild.bat && node --version && node release-wasm64\\wasm-alloc.js")
12+
else:
13+
with chdir("build/release-wasm"):
14+
run(". generators/conanbuild.sh && node --version && node release-wasm/wasm-alloc.js")
15+
# Needs at least Node.js 24.0.0
16+
# run(". generators/conanbuild.sh && node --version && node release-wasm64/wasm-alloc.js")
17+

examples/cross_build/wasm/wasm_game/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ target_link_libraries(wasm_game raylib)
99

1010
# Set the executable suffix to .html in order to generate a html page by
1111
# Emscripten (there is no way of setting this from a user toolchain or
12-
# conanfile as it is later overriden by the emscripten toolchain)
12+
# conanfile as it is later overridden by the Emscripten toolchain)
1313
set(CMAKE_EXECUTABLE_SUFFIX ".html")

examples/cross_build/wasm/wasm_game/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ This project is a copy of our [raylib](https://github.com/conan-io/examples2/tre
44

55
It has minor modifications:
66

7-
- C++ source code has been modified in order to accept mouse clicks as inputs as it is more convenient for a webpage
8-
- `CMakeLists.txt` has been modified in order to link against raylib correctly using WASM
7+
- C++ source code has been slightly modified in order to accept mouse clicks as inputs as it is more convenient for a webpage
8+
- `CMakeLists.txt` has been modified in order to generate a `html` target which can bee opened by a web browser
9+
- `conanfile.py` `generate()` method has been modified in order to link against raylib correctly using WASM
910
- `-sUSE_GLFW=3 -sASYNCIFY`: see [raylib web manual](https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5)#23-using-cmake) for a deeper explanation
1011
- `--shell-file`: generate the html code from the template
1112

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
from test.examples_tools import run
3+
4+
run("conan build . --build=missing --profile:host ../profiles/wasm32")
5+
6+
assert os.path.exists(os.path.join("build", "release-wasm", "wasm_game.html"))
7+
assert os.path.exists(os.path.join("build", "release-wasm", "wasm_game.js"))
8+
assert os.path.exists(os.path.join("build", "release-wasm", "wasm_game.wasm"))

0 commit comments

Comments
 (0)