Skip to content

Commit

Permalink
Initial support for wasmtime package
Browse files Browse the repository at this point in the history
  • Loading branch information
redradist committed Jul 1, 2021
1 parent 39a9ad7 commit dc8865a
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/wasmtime/all/CMakeLists.txt
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)
2 changes: 2 additions & 0 deletions recipes/wasmtime/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sources:
"0.28.0": ""
79 changes: 79 additions & 0 deletions recipes/wasmtime/all/conanfile.py
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']
12 changes: 12 additions & 0 deletions recipes/wasmtime/all/test_package/CMakeLists.txt
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)
17 changes: 17 additions & 0 deletions recipes/wasmtime/all/test_package/conanfile.py
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)
10 changes: 10 additions & 0 deletions recipes/wasmtime/all/test_package/example.cpp
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;
}
3 changes: 3 additions & 0 deletions recipes/wasmtime/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.28.0":
folder: all

0 comments on commit dc8865a

Please sign in to comment.