Skip to content

Commit e36b5b3

Browse files
authored
Patch Embind generation for string types in TypeScript
1 parent 0d68e90 commit e36b5b3

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

recipes/emsdk/all/conanfile.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import json
88
import os
99

10-
1110
required_conan_version = ">=1.52.0"
1211

1312

@@ -109,6 +108,16 @@ def build(self):
109108
self.run(f"{emsdk} install {value}")
110109
self.run(f"{emsdk} activate {value}")
111110

111+
# Patch to fix the TypeScript generation of std::string (C++) -> string (TS)
112+
# This is a deviation from upstream recipe
113+
replace_in_file(self, os.path.join(self.build_folder, "..", "src", "upstream", "emscripten", "src", "embind",
114+
"embind_gen.js"), "['std::string', [jsString, 'string']],",
115+
"['std::string', ['string']],")
116+
replace_in_file(self, os.path.join(self.build_folder, "..", "src", "upstream", "emscripten", "src", "embind",
117+
"embind_gen.js"),
118+
"['std::basic_string<unsigned char>', [jsString, 'string']],",
119+
"['std::basic_string<unsigned char>', ['string']],")
120+
112121
def package(self):
113122
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
114123
copy(self, "*", src=self.source_folder, dst=os.path.join(self.package_folder, "bin"))
@@ -117,16 +126,16 @@ def package(self):
117126
# FIXME: conan should add the root of conan package requirements to CMAKE_PREFIX_PATH (LIBRARY/INCLUDE -> ONLY; PROGRAM -> NEVER)
118127
# allow to find conan libraries
119128
replace_in_file(self, toolchain,
120-
"set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)",
121-
"set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)")
129+
"set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)",
130+
"set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)")
122131
replace_in_file(self, toolchain,
123-
"set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)",
124-
"set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)")
132+
"set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)",
133+
"set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)")
125134
replace_in_file(self, toolchain,
126-
"set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)",
127-
"set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)")
135+
"set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)",
136+
"set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)")
128137
if not cross_building(self):
129-
self.run("embuilder build MINIMAL", env=["conanemsdk", "conanrun"]) # force cache population
138+
self.run("embuilder build MINIMAL", env=["conanemsdk", "conanrun"]) # force cache population
130139
# the line below forces emscripten to accept the cache as-is, even after re-location
131140
# https://github.com/emscripten-core/emscripten/issues/15053#issuecomment-920950710
132141
os.remove(os.path.join(self._em_cache, "sanity.txt"))
@@ -150,16 +159,18 @@ def package_info(self):
150159
return
151160

152161
if self.settings_target.os != "Emscripten":
153-
self.output.warning(f"You've added {self.name}/{self.version} as a build requirement, while os={self.settings_target.os} != Emscripten")
162+
self.output.warning(
163+
f"You've added {self.name}/{self.version} as a build requirement, while os={self.settings_target.os} != Emscripten")
154164
return
155165

156-
toolchain = os.path.join(self.package_folder, "bin", "upstream", "emscripten", "cmake", "Modules", "Platform", "Emscripten.cmake")
166+
toolchain = os.path.join(self.package_folder, "bin", "upstream", "emscripten", "cmake", "Modules", "Platform",
167+
"Emscripten.cmake")
157168
self.conf_info.prepend("tools.cmake.cmaketoolchain:user_toolchain", toolchain)
158169

159170
self.buildenv_info.define_path("EMSDK", self._emsdk)
160171
self.buildenv_info.define_path("EMSCRIPTEN", self._emscripten)
161172
self.buildenv_info.define_path("EM_CONFIG", self._em_config)
162-
self.buildenv_info.define_path("EM_CACHE", self._em_cache)
173+
self.buildenv_info.define_path("EM_CACHE", self._em_cache)
163174

164175
compiler_executables = {
165176
"c": self._define_tool_var("emcc"),

0 commit comments

Comments
 (0)