diff --git a/recipes/wasmtime/all/conandata.yml b/recipes/wasmtime/all/conandata.yml new file mode 100644 index 0000000000000..03207b0b9b262 --- /dev/null +++ b/recipes/wasmtime/all/conandata.yml @@ -0,0 +1,25 @@ +sources: + "0.29.0": + Windows: + "x86_64": + url: "https://github.com/bytecodealliance/wasmtime/releases/download/v0.29.0/wasmtime-v0.29.0-x86_64-windows-c-api.zip" + sha256: "57ba0732597c2fd8717738067e4067ff571f11ed87b32bd251fe0335bee107af" + MinGW: + "x86_64": + url: "https://github.com/bytecodealliance/wasmtime/releases/download/v0.29.0/wasmtime-v0.29.0-x86_64-mingw-c-api.zip" + sha256: "9c5c5c2baa624a04506474ca488c875d4fd99268370e74eb4ce12e6d9db767d4" + Linux: + "x86_64": + url: "https://github.com/bytecodealliance/wasmtime/releases/download/v0.29.0/wasmtime-v0.29.0-x86_64-linux-c-api.tar.xz" + sha256: "e94a9a768270e86e7f7eac1a68575bb1f287702822e83b14c3b04bf7e865a84c" + "armv8": + url: "https://github.com/bytecodealliance/wasmtime/releases/download/v0.29.0/wasmtime-v0.29.0-aarch64-linux-c-api.tar.xz" + sha256: "36a257aef36f5a0cabc8ce414e31ccede9c16ca996d6b07cb440a32aaa263164" + Macos: + "x86_64": + url: "https://github.com/bytecodealliance/wasmtime/releases/download/v0.29.0/wasmtime-v0.29.0-x86_64-macos-c-api.tar.xz" + sha256: "d80209990661e7cf8ae7a2db4ba931cd61da27e7956be05baf8cfe24d1951283" + Android: + "armv8": + url: "https://github.com/bytecodealliance/wasmtime/releases/download/v0.29.0/wasmtime-v0.29.0-aarch64-linux-c-api.tar.xz" + sha256: "36a257aef36f5a0cabc8ce414e31ccede9c16ca996d6b07cb440a32aaa263164" diff --git a/recipes/wasmtime/all/conanfile.py b/recipes/wasmtime/all/conanfile.py new file mode 100644 index 0000000000000..96990538aa4a3 --- /dev/null +++ b/recipes/wasmtime/all/conanfile.py @@ -0,0 +1,105 @@ +from conans import ConanFile, CMake, tools +from conans.errors import ConanInvalidConfiguration, ConanException +import os +import shutil + +required_conan_version = ">=1.33.0" + +class WasmtimeConan(ConanFile): + name = 'wasmtime' + homepage = 'https://github.com/bytecodealliance/wasmtime' + license = 'Apache-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", "arch" + options = { "shared": [True, False] } + default_options = { 'shared': False } + no_copy_source = True + + @property + def _minimum_cpp_standard(self): + return 11 + + @property + def _minimum_compilers_version(self): + return { + "Visual Studio": "15", + "apple-clang": "9.4", + "clang": "3.3", + "gcc": "5.1" + } + + @property + def _sources_key(self): + if self.settings.compiler == "Visual Studio": + return "Windows" + elif self.settings.os == "Windows" and self.settings.compiler == "gcc": + return "MinGW" + return str(self.settings.os) + + def configure(self): + del self.settings.compiler.libcxx + del self.settings.compiler.cppstd + del self.settings.compiler.runtime + + def validate(self): + compiler = self.settings.compiler + min_version = self._minimum_compilers_version[str(compiler)] + try: + if tools.Version(compiler.version) < min_version: + msg = ( + "{} requires C{} features which are not supported by compiler {} {} !!" + ).format(self.name, self._minimum_cpp_standard, compiler, compiler.version) + raise ConanInvalidConfiguration(msg) + except KeyError: + msg = ( + "{} recipe lacks information about the {} compiler, " + "support for the required C{} features is assumed" + ).format(self.name, compiler, self._minimum_cpp_standard) + self.output.warn(msg) + + try: + self.conan_data["sources"][self.version][self._sources_key][str(self.settings.arch)] + except KeyError: + raise ConanInvalidConfiguration("Binaries for this combination of architecture/version/os not available") + + if (self.settings.compiler, self.settings.os) == ("gcc", "Windows") and self.options.shared: + # FIXME: https://github.com/bytecodealliance/wasmtime/issues/3168 + raise ConanInvalidConfiguration("Shared mingw is currently not possible") + + def source(self): + tools.get(**self.conan_data["sources"][self.version][self._sources_key][str(self.settings.arch)], destination=self.source_folder, strip_root=True) + + def package(self): + shutil.copytree(os.path.join(self.source_folder, "include"), + os.path.join(self.package_folder, "include")) + + srclibdir = os.path.join(self.source_folder, "lib") + if self.options.shared: + self.copy("wasmtime.dll.lib", src=srclibdir, dst="lib", keep_path=False) + self.copy("wasmtime.dll", src=srclibdir, dst="bin", keep_path=False) + self.copy("libwasmtime.dll.a", src=srclibdir, dst="lib", keep_path=False) + self.copy("libwasmtime.so*", src=srclibdir, dst="lib", keep_path=False) + self.copy("libwasmtime.dylib", src=srclibdir, dst="lib", keep_path=False) + else: + self.copy("wasmtime.lib", src=srclibdir, dst="lib", keep_path=False) + self.copy("libwasmtime.a", src=srclibdir, dst="lib", keep_path=False) + + self.copy('LICENSE', dst='licenses', src=self.source_folder) + + def package_info(self): + if self.options.shared: + if self.settings.os == "Windows": + self.cpp_info.libs = ["wasmtime.dll"] + else: + 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"] + + if self.settings.os == 'Windows': + self.cpp_info.system_libs = ['ws2_32', 'bcrypt', 'advapi32', 'userenv', 'ntdll', 'shell32', 'ole32'] + elif 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 0000000000000..1d451da128fdc --- /dev/null +++ b/recipes/wasmtime/all/test_package/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.1) +project(PackageTest C) + +set(CMAKE_C_STANDARD 11) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +find_package(wasmtime REQUIRED) + +add_executable(example example.c) +target_link_libraries(example PRIVATE wasmtime::wasmtime) +target_compile_options(example PRIVATE ${CONAN_COMPILE_DEFINITIONS_WASMTIME}) diff --git a/recipes/wasmtime/all/test_package/conanfile.py b/recipes/wasmtime/all/test_package/conanfile.py new file mode 100644 index 0000000000000..a3c91f5c3e0ac --- /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): + bin_path = os.path.join('bin', 'example') + self.run(bin_path, run_environment=True) diff --git a/recipes/wasmtime/all/test_package/example.c b/recipes/wasmtime/all/test_package/example.c new file mode 100644 index 0000000000000..7798660541456 --- /dev/null +++ b/recipes/wasmtime/all/test_package/example.c @@ -0,0 +1,8 @@ +#include + +int main() { + char* wat = ""; + wasm_byte_vec_t ret; + wasmtime_error_t *error = wasmtime_wat2wasm(wat, sizeof(wat), &ret); + return 0; +} diff --git a/recipes/wasmtime/config.yml b/recipes/wasmtime/config.yml new file mode 100644 index 0000000000000..2082bc997baf0 --- /dev/null +++ b/recipes/wasmtime/config.yml @@ -0,0 +1,3 @@ +versions: + "0.29.0": + folder: all