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

Initial support for wasmtime package #6083

Merged
merged 25 commits into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
455e9a4
Initial support for wasmtime package
redradist Jun 29, 2021
15736c9
Fixed build package on Linux
redradist Jul 3, 2021
30ad84c
Updates according the comments in review #0
redradist Jul 4, 2021
638e944
Merge branch 'add-wasmtime' of github.com:redradist/conan-center-inde…
redradist Jul 4, 2021
326e85d
Update recipes/wasmtime/all/conanfile.py
redradist Jul 4, 2021
43445ea
Updates according the comments in review #1
redradist Jul 4, 2021
2746861
Merge branch 'add-wasmtime' of github.com:redradist/conan-center-inde…
redradist Jul 4, 2021
45b7d00
Updates according the comments in review #2
redradist Jul 4, 2021
7aa47ca
Updates according the comments in review #3
redradist Jul 5, 2021
dddb52d
Updates according the comments in review #4
redradist Jul 10, 2021
fe85d9e
Updates according the comments in review #5
redradist Jul 10, 2021
c3a4642
Next iteration of fixes
redradist Jul 25, 2021
6304223
Fixed cmake variable C_STANDARD -> CMAKE_C_STANDARD
redradist Jul 28, 2021
c75ea1a
Added check on minimal version of conan
redradist Jul 28, 2021
2e49fa7
Used copytree instead of copy individual files
redradist Aug 2, 2021
8af9461
Fixed the build
redradist Aug 14, 2021
7b0b19c
Added checking for architechure in validate(...)
redradist Aug 14, 2021
728690c
Updated receipt for new comments from @madebr
redradist Aug 14, 2021
59f9c9f
Fixed calling method tools.cross_building(...)
redradist Aug 14, 2021
dca562b
Update def package(self) according the comments in review
redradist Aug 22, 2021
7eeed40
Updated versions of wasmtime
redradist Aug 30, 2021
c1fa065
Updated forgot version ugrade
redradist Aug 30, 2021
20d43a9
Fixed sha256sum for macos
redradist Aug 30, 2021
ed7f493
Fixed SHA256 for Linux
redradist Aug 30, 2021
3012cca
Updated all SHA256 to proer values
redradist Aug 30, 2021
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
25 changes: 25 additions & 0 deletions recipes/wasmtime/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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: "83d42ab6b78804f6dcd58f4bfc1bebb3a56a21309fce28e07a5bfbecc07dc8fa"
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: "d44b1345a7e3f86c71af6cc225b83bdb3aef874fb1eaac7a8f06ad3b3a6a5c3e"
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: "b8ee53ddebfc60a0cf981ce225837b998b984ee94326e03cac135d9d78af57e5"
"armv8":
url: "https://github.com/bytecodealliance/wasmtime/releases/download/v0.29.0/wasmtime-v0.29.0-aarch64-linux-c-api.tar.xz"
sha256: "c13f906ca84c3321644cb9cd93fef4db431572e554a7527dc30a795994cbcc05"
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: "e6e38b1837509af3ce5ca490d90c59d6082f54eb71dcbb49414ee5f295137bcb"
Android:
"armv8":
url: "https://github.com/bytecodealliance/wasmtime/releases/download/v0.29.0/wasmtime-v0.29.0-aarch64-linux-c-api.tar.xz"
sha256: "c9036f82c2fb2c3ed8291c6d37068dce6b08dff83f6292938edc0c8907284549"
105 changes: 105 additions & 0 deletions recipes/wasmtime/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
homepage = 'https://github.com/bytecodealliance/wasmtime'
homepage = 'https://wasmtime.dev/'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disagree, because later I will add package for wasmtime-cpp and it would be weird to have two projects with the same home directory

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those should be the same recipe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be separate receipts wasmtime (only C API) and wasmtime-cpp (C++ API)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also https://wasmtime.dev/ is not descriptive enough for understanding how to use this package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you will still need this package
As I mentioned previously I will create support with dependency on this package when I will create wasmtime-cpp
See the issue:
bytecodealliance/wasmtime-cpp#1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay to have two recipes share the same homepage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Home page should be meaningful
https://wasmtime.dev/ does not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you're right.
The c api lives in the main/crates/c-api subfolder.

How does this project relate to wasm-c-api at https://github.com/WebAssembly/wasm-c-api/?

Copy link
Contributor Author

@redradist redradist Jul 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@madebr It is unrelated project

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was merged in

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, but we will need to wait for the next release to have shared mingw avaialble.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I did not look, but thats for checking!

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="]
Copy link
Contributor

@prince-chrismc prince-chrismc Jul 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conan should handle the rest

Suggested change
self.cpp_info.defines= ["/DWASM_API_EXTERN=", "/DWASI_API_EXTERN="]
self.cpp_info.defines.extend(["WASM_API_EXTERN", "WASI_API_EXTERN"])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without /D conan generates some strange defines and test_package does not work:

set(CONAN_DEFINES_WASMTIME "-DWASM_API_EXTERN"
			"-DWASI_API_EXTERN")
set(CONAN_BUILD_MODULES_PATHS_WASMTIME )
# COMPILE_DEFINITIONS are equal to CONAN_DEFINES without -D, for targets
set(CONAN_COMPILE_DEFINITIONS_WASMTIME "WASM_API_EXTERN"
			"WASI_API_EXTERN")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for a lot of other recipes. https://github.com/conan-io/conan-center-index/search?p=2&q=cpp_info+defines

You need to use it in tandem with the other comment https://github.com/conan-io/conan-center-index/pull/6083/files#r663361146

I update the suggestion with a better syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better syntax, but it is not working ...
Please, check it locally in Windows machine

self.cpp_info.libs = ["wasmtime"]
Comment on lines +92 to +100
Copy link
Contributor

@madebr madebr Jul 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you do the rename of the import library in https://github.com/conan-io/conan-center-index/pull/6083/files#r670899230, then these lines can become:

Suggested change
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"]
libsuffix = ""
if self.settings.os == "Windows":
if self.options.shared:
libsuffix = ".dll"
else:
self.cpp_info.defines.extend(["WASM_API_EXTERN", "WASI_API_EXTERN"])
self.cpp_info.libs = ["wasmtime" + libsuffix]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You miss wasmtime.dll in your suggestion

This package has library like this wasmtime.dll.lib

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated my suggestion.

Copy link
Contributor Author

@redradist redradist Jul 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"WASM_API_EXTERN", "WASI_API_EXTERN" does not work on Windows

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. The _EXTERN are used directly in front of the function.
WASI_API_EXTERN is used here: https://github.com/bytecodealliance/wasmtime/blob/6f3adacb9fb37043d77279b90e63517b07628011/crates/c-api/include/wasi.h#L12-L18

I've updated the suggestion again.

Copy link
Contributor Author

@redradist redradist Jul 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see any updates ...
Only way it works like this:
"/DWASM_API_EXTERN="
"/DWASI_API_EXTERN="

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not translated to proper MSVC flag

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What client version and generator are you using?

I use this and it works perfectly

if self.options.get_safe("pplx_impl") == "winpplx":
self.cpp_info.components["cpprest"].defines.append("CPPREST_FORCE_PPLX=1")
if self.options.get_safe("http_client_impl") == "asio":
self.cpp_info.components["cpprest"].defines.append("CPPREST_FORCE_HTTP_CLIENT_ASIO")


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']
13 changes: 13 additions & 0 deletions recipes/wasmtime/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
redradist marked this conversation as resolved.
Show resolved Hide resolved
target_compile_options(example PRIVATE ${CONAN_COMPILE_DEFINITIONS_WASMTIME})
Copy link
Contributor

@prince-chrismc prince-chrismc Jul 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be included with the targets

Suggested change
target_compile_options(example PRIVATE ${CONAN_COMPILE_DEFINITIONS_WASMTIME})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot do this, because wasmtime::wasmtime do not have compile definitions for this target ...
By some reason conan do not add target_compile_definitions(...) for this target

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also very strange behavior:

set(CONAN_DEFINES_WASMTIME "-D/DWASM_API_EXTERN="
			"-D/DWASI_API_EXTERN=")
set(CONAN_BUILD_MODULES_PATHS_WASMTIME )
# COMPILE_DEFINITIONS are equal to CONAN_DEFINES without -D, for targets
set(CONAN_COMPILE_DEFINITIONS_WASMTIME "/DWASM_API_EXTERN="
			"/DWASI_API_EXTERN=")

CONAN_COMPILE_DEFINITIONS_WASMTIME generated properly, but CONAN_DEFINES_WASMTIME is incorrect

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it is not, see comment above for it

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'
redradist marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use cmake_find_package.
Because upstream wasmtime does not provide cmake targets, we don't test/use it in a test package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It breaks build

wasmtime::wasmtime helps in way to add all includes and necessary flags

I do not see any issue with verifing using cmake_find_package because I verify linking with test_package

Copy link
Contributor

@madebr madebr Aug 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What breaks? It should not.
If it breaks somewhere, that means something else is wrong.

I tested my pr on Linux and Windows.

Copy link
Contributor Author

@redradist redradist Aug 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@madebr If something else would be wrong that Ci did not pass ...

The difference between wasmtime::wasmtime and ${CONAN_LIBS} is that wasmtime::wasmtime implicitly include: include libraries, defines and etc.

It is just much easier to write with wasmtime::wasmtime than with ${CONAN_LIBS}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@madebr If something else would be wrong that Ci did not pass ...

I don't understand this.

The difference between wasmtime::wasmtime and ${CONAN_LIBS} is that wasmtime::wasmtime implicitly include: include libraries, defines and etc.

It is just much easier to write with wasmtime::wasmtime than with ${CONAN_LIBS}

Easy is relative.
Right now you're mixing global includes and a cmake target, which is even more potentially troubling.

I'm referring to this section in the docs: https://github.com/conan-io/conan-center-index/blob/master/docs/reviewing.md#test-package
Because wasmtime does not export a wasmtime cmake_find_package generator name, it's not tested.


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)
8 changes: 8 additions & 0 deletions recipes/wasmtime/all/test_package/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <wasmtime.h>

int main() {
char* wat = "";
wasm_byte_vec_t ret;
wasmtime_error_t *error = wasmtime_wat2wasm(wat, sizeof(wat), &ret);
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.29.0":
folder: all