From dc8865aab3c8f87fda9ec0c65f539e206989cbe7 Mon Sep 17 00:00:00 2001 From: redradist Date: Tue, 29 Jun 2021 12:12:24 +0300 Subject: [PATCH] Initial support for wasmtime package --- recipes/wasmtime/all/CMakeLists.txt | 7 ++ recipes/wasmtime/all/conandata.yml | 2 + recipes/wasmtime/all/conanfile.py | 79 +++++++++++++++++++ .../wasmtime/all/test_package/CMakeLists.txt | 12 +++ .../wasmtime/all/test_package/conanfile.py | 17 ++++ recipes/wasmtime/all/test_package/example.cpp | 10 +++ recipes/wasmtime/config.yml | 3 + 7 files changed, 130 insertions(+) create mode 100644 recipes/wasmtime/all/CMakeLists.txt create mode 100644 recipes/wasmtime/all/conandata.yml create mode 100644 recipes/wasmtime/all/conanfile.py create mode 100644 recipes/wasmtime/all/test_package/CMakeLists.txt create mode 100644 recipes/wasmtime/all/test_package/conanfile.py create mode 100644 recipes/wasmtime/all/test_package/example.cpp create mode 100644 recipes/wasmtime/config.yml diff --git a/recipes/wasmtime/all/CMakeLists.txt b/recipes/wasmtime/all/CMakeLists.txt new file mode 100644 index 00000000000000..bd3083b512cb93 --- /dev/null +++ b/recipes/wasmtime/all/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.1) +project(cmake_wrapper) + +include(conanbuildinfo.cmake) +conan_basic_setup() + +add_subdirectory(source_subfolder) diff --git a/recipes/wasmtime/all/conandata.yml b/recipes/wasmtime/all/conandata.yml new file mode 100644 index 00000000000000..a510977a9d94a4 --- /dev/null +++ b/recipes/wasmtime/all/conandata.yml @@ -0,0 +1,2 @@ +sources: + "0.28.0": "" diff --git a/recipes/wasmtime/all/conanfile.py b/recipes/wasmtime/all/conanfile.py new file mode 100644 index 00000000000000..ee7fed1df12227 --- /dev/null +++ b/recipes/wasmtime/all/conanfile.py @@ -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'] diff --git a/recipes/wasmtime/all/test_package/CMakeLists.txt b/recipes/wasmtime/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000000..fe1abffa28c4f0 --- /dev/null +++ b/recipes/wasmtime/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/wasmtime/all/test_package/conanfile.py b/recipes/wasmtime/all/test_package/conanfile.py new file mode 100644 index 00000000000000..b92626c3778c4e --- /dev/null +++ b/recipes/wasmtime/all/test_package/conanfile.py @@ -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) diff --git a/recipes/wasmtime/all/test_package/example.cpp b/recipes/wasmtime/all/test_package/example.cpp new file mode 100644 index 00000000000000..dc458016aa6252 --- /dev/null +++ b/recipes/wasmtime/all/test_package/example.cpp @@ -0,0 +1,10 @@ +#include +#include + +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; +} diff --git a/recipes/wasmtime/config.yml b/recipes/wasmtime/config.yml new file mode 100644 index 00000000000000..e64ed6c037d2c4 --- /dev/null +++ b/recipes/wasmtime/config.yml @@ -0,0 +1,3 @@ +versions: + "0.28.0": + folder: all