Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve wasmtime recipe #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 32 additions & 44 deletions recipes/wasmtime/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@

class WasmtimeConan(ConanFile):
name = 'wasmtime'
homepage = 'https://github.com/bytecodealliance/wasmtime'
homepage = 'https://wasmtime.dev'
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],
'fPIC': [True],
}
default_options = {
'shared': False,
'fPIC': True,
}
no_copy_source = True

@property
def _source_subfolder(self):
return "source_subfolder"
options = {"shared": [True, False]}
default_options = {"shared": False}

@property
def _minimum_cpp_standard(self):
Expand All @@ -35,18 +24,12 @@ def _minimum_compilers_version(self):
"Visual Studio": "15",
"apple-clang": "9.4",
"clang": "3.3",
"gcc": "4.9.4"
"gcc": "4.9"
}

def config_options(self):
if self.settings.os == 'Windows':
del self.options.fPIC

def configure(self):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
if self.options.shared:
del self.options.fPIC
@property
def _source_subfolder(self):
return "source_subfolder"

def validate(self):
compiler = self.settings.compiler
Expand All @@ -60,7 +43,7 @@ def validate(self):
except KeyError:
msg = (
"{} recipe lacks information about the {} compiler, "
"support for the required C++{} features is assumed"
"support for the required C{} features is assumed"
).format(self.name, compiler, self._minimum_cpp_standard)
self.output.warn(msg)

Expand All @@ -69,35 +52,40 @@ def validate(self):
not (str(self.settings.arch) in self.conan_data["sources"][self.version][str(self.settings.os)] ) ):
raise ConanInvalidConfiguration("Binaries for this combination of architecture/version/os not available")

def source(self):
tools.get(**self.conan_data["sources"][self.version][str(self.settings.os)][str(self.settings.arch)], destination=self._source_subfolder, strip_root=True)
def build(self):
tools.get(**self.conan_data["sources"][self.version][str(self.settings.os)][str(self.settings.arch)],
destination=self._source_subfolder, strip_root=True)

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):
if self.options.shared:
self.copy('*.dll', dst='bin', keep_path=False)
self.copy('*.dll.lib', dst='lib', keep_path=False)
self.copy('*.so', dst='lib', keep_path=False)
self.copy('*.dylib', dst='lib', keep_path=False)
if self.settings.os == "Windows":
self.cpp_info.libs = ["wasmtime.dll"]
else:
self.cpp_info.libs = ["wasmtime"]
tools.rename(os.path.join(self.package_folder, "lib", "wasmtime.dll.lib"),
os.path.join(self.package_folder, "lib", "wasmtime.lib"))
else:
if self.settings.os == "Windows":
self.cpp_info.defines= ["/DWASM_API_EXTERN=", "/DWASI_API_EXTERN="]
self.cpp_info.libs = ["wasmtime"]
self.copy('*.lib', dst='lib', excludes="*.dll.lib", keep_path=False)
self.copy('*.a', dst='lib', keep_path=False)

if self.settings.os == 'Windows':
self.copy('LICENSE', dst='licenses', src=self._source_subfolder)

def package_id(self):
del self.info.settings.compiler

def package_info(self):
self.cpp_info.libs = ["wasmtime"]
if self.settings.os == "Windows":
if not self.options.shared:
# FIXME: Tricky way to pass definions. cpp_info.define does not work.
self.cpp_info.cflags = ["-DWASM_API_EXTERN=", "-DWASI_API_EXTERN="]
self.cpp_info.cxxflags = ["-DWASM_API_EXTERN=", "-DWASI_API_EXTERN="]
self.cpp_info.system_libs = ['ws2_32', 'bcrypt', 'advapi32', 'userenv', 'ntdll', 'shell32', 'ole32']
if self.settings.os == 'Linux':
elif self.settings.os == 'Linux':
self.cpp_info.system_libs = ['pthread', 'dl', 'm']
11 changes: 4 additions & 7 deletions recipes/wasmtime/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(PackageTest)

set(C_STANDARD 11)
project(PackageTest C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
conan_basic_setup(TARGETS)

find_package(wasmtime REQUIRED)
find_package(wasmtime REQUIRED CONFIG)

add_executable(example example.c)
target_link_libraries(example PRIVATE wasmtime::wasmtime)
target_compile_options(example PRIVATE ${CONAN_COMPILE_DEFINITIONS_WASMTIME})
target_link_libraries(example wasmtime::wasmtime)
2 changes: 1 addition & 1 deletion recipes/wasmtime/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class WasmtimeTestConan(ConanFile):
settings = 'os', 'compiler', 'build_type', 'arch'
generators = 'cmake', 'cmake_find_package'
generators = 'cmake', 'cmake_find_package_multi'

def build(self):
cmake = CMake(self)
Expand Down