-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for wasmtime package
- Loading branch information
Showing
7 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(cmake_wrapper) | ||
|
||
include(conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
add_subdirectory(source_subfolder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
sources: | ||
"0.28.0": "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from conans import ConanFile, CMake, tools | ||
from conans.errors import ConanInvalidConfiguration, ConanException | ||
import os | ||
|
||
|
||
class WasmtimeConan(ConanFile): | ||
name = 'wasmtime' | ||
homepage = 'https://github.com/bytecodealliance/wasmtime' | ||
license = 'Apache License 2.0' | ||
url = 'https://github.com/conan-io/conan-center-index' | ||
description = "Standalone JIT-style runtime for WebAssembly, using Cranelift" | ||
topics = ("webassembly", "wasm", "wasi") | ||
settings = "os", "compiler", "build_type", "arch" | ||
options = { | ||
"shared": [True, False], | ||
'fPIC': [True], | ||
} | ||
default_options = { | ||
'shared': False, | ||
'fPIC': True, | ||
} | ||
generators = "cmake", "cmake_find_package", "cmake_find_package_multi" | ||
exports_sources = ['CMakeLists.txt', 'patches/*'] | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
|
||
def config_options(self): | ||
if self.settings.os == 'Windows': | ||
del self.options.fPIC | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
del self.options.fPIC | ||
|
||
def build(self): | ||
try: | ||
if self.settings.arch == "armv8" and self.settings.os == "Android": | ||
os_name = "Linux" | ||
else: | ||
os_name = str(self.settings.os) | ||
|
||
archive_ext = "zip" if os_name == "Windows" else "tar.xz" | ||
url = f"https://github.com/bytecodealliance/wasmtime/releases/download/v{self.version}/wasmtime-v{self.version}-{self.settings.arch}-{os_name.lower()}-c-api.{archive_ext}" | ||
tools.get(url, strip_root=True, destination=self._source_subfolder) | ||
except: | ||
raise Exception("Binary does not exist for these settings") | ||
|
||
def package(self): | ||
include_path = os.path.join(self._source_subfolder, 'include') | ||
self.copy('*.h', dst='include', src=include_path) | ||
self.copy('*.hh', dst='include', src=include_path) | ||
self.copy('*.hpp', dst='include', src=include_path) | ||
|
||
self.copy('*.lib', dst='lib', keep_path=False) | ||
self.copy('*.dll', dst='bin', keep_path=False) | ||
self.copy('*.so', dst='lib', keep_path=False) | ||
self.copy('*.dylib', dst='lib', keep_path=False) | ||
self.copy('*.a', dst='lib', keep_path=False) | ||
|
||
self.copy('LICENSE', dst='licenses', src=self._source_subfolder) | ||
|
||
def package_info(self): | ||
self.cpp_info.names["cmake_find_package"] = "wasmtime" | ||
self.cpp_info.names["cmake_find_multi_package"] = "wasmtime" | ||
if self.options.shared: | ||
self.cpp_info.libs = ["wasmtime"] | ||
else: | ||
if self.settings.os == "Windows": | ||
self.cpp_info.defines= ["/DWASM_API_EXTERN=", "/DWASI_API_EXTERN="] | ||
self.cpp_info.libs = ["wasmtime.dll"] | ||
else: | ||
self.cpp_info.libs = ["wasmtime"] | ||
|
||
if self.settings.os == 'Windows': | ||
self.cpp_info.system_libs = ['ws2_32', 'bcrypt', 'advapi32', 'userenv', 'ntdll', 'shell32', 'ole32'] | ||
if self.settings.os == 'Linux': | ||
self.cpp_info.system_libs = ['pthread', 'dl', 'm'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(PackageTest) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
find_package(wasmtime REQUIRED) | ||
|
||
add_executable(example example.cpp) | ||
target_link_libraries(example PRIVATE wasmtime::wasmtime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from conans import ConanFile, CMake, tools | ||
import os | ||
|
||
|
||
class WasmtimeTestConan(ConanFile): | ||
settings = 'os', 'compiler', 'build_type', 'arch' | ||
generators = 'cmake', 'cmake_find_package' | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not tools.cross_building(self.settings): | ||
bin_path = os.path.join('bin', 'example') | ||
self.run(bin_path, run_environment=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <thread> | ||
#include <wasmtime.h> | ||
|
||
int main() { | ||
auto wat = ""; | ||
wasm_byte_vec_t ret; | ||
auto *error = wasmtime_wat2wasm(wat, sizeof(wat), &ret); | ||
std::this_thread::sleep_for(std::chrono::seconds(1)); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"0.28.0": | ||
folder: all |