-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Use cmake to build wasmtime-c-api #9031
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Do you know if it's possible to have an install target which only installs header files? That way there wouldn't need to be two includes and only one would be necessary.
Additionally can you forward along the -D
flags for the features of Wasmtime? Otherwise the conf.h
could report the wrong set of supported features.
Sure, we just need to use Are you suggesting that instead of just generating the header, I install all the headers to the cargo output directory, and then report that as the sole include directory? That makes sense, I just want to confirm. |
Updated commits properly configure the headers, and install all headers to the right place, so we can get rid of the second metadata variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Can this be backported to release-23, too? |
I think that would be reasonable yeah, just needs to land on I believe CI is failing here on MinGW for cmake-related reasons? (compiler detection not working presumbably because |
Is there any way we could avoid adding this Could the Maybe I'm missing something, and the CMake build is doing something too significant to duplicate, but if not, it would be great to avoid the build-time dependency. |
Is the |
I just anticipate that consumers of the Just to double check, I think that if we wanted to avoid requiring Cmake, we'd change this: let dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let mut config = cmake::Config::new(&dir);
config
.define("WASMTIME_DISABLE_ALL_FEATURES", "ON")
.always_configure(true)
.build_target("headers");
for f in FEATURES {
if env::var_os(format!("CARGO_FEATURE_{}", f)).is_some() {
config.define(format!("WASMTIME_FEATURE_{}", f), "ON");
}
}
let dst = config.build(); into this (or something similar). let prefix = "#ifndef WASMTIME_CONF_H\n#define WASMTIME_CONF_H\n";
let suffix = "#endif\n";
let mut header = prefix.to_string();
for f in FEATURES {
if std::env::var_os(format!("CARGO_FEATURE_{}", f)).is_some() {
writeln!(&mut header, "WASMTIME_FEATURE_{}", f);
}
}
header += suffix; And you wouldn't need to add the |
The brittle part is that it's a duplication of copying over headers and there is no longer a single source of truth for how headers are created. Additionally there are no tests in this repository testing the header as-generated by the build script and without that there's also no tests that the duplicated logic for the header file generation is correct. What you're describing is correct as-is today but that may not hold true indefinitely into the future. |
Edit - Sorry never mind, it doesn't matter that much, and I don't want to hold this up. |
Is there are test that mingw compilation is working at all presently? This invocation of cmake looks correct, but it detects MSVC anyways:
UpdatedLooking at another mingw job I see that |
I've added a workflow change to include the commands that I suspect fix the issue. And I rebased. |
I've added an extra commit to this PR which runs the full tests suite on this PR instead of waiting for the merge queue, and it looks like there may still be some CI issues |
d1cfcef
to
560b2a0
Compare
The one remaining CI failure is a network failure. Changes made to make CI happy:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Given the possible fragility here with packaging and how you had to modify include
, could verification via publish.rs
be made to work? Basically could this be updated to undo the addition of --no-verify
?
As for wasi-nn, if you'd like I think it's reasonable to try dropping that here too (and verify it), but it's ok to defer that to a different PR as well.
crates/c-api/CMakeLists.txt
Outdated
# Note: this line will *always* create ${CMAKE_CURRENT_SOURCE_DIR}/artifact | ||
# during the configure stage of cmake, and there does not seem to be a way to | ||
# disable this behavior. This prevents cargo package from verifying the package. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the BINARY_DIR
configuration be dropped entirely? That should probably be somewhere within CMAKE_CURRENT_BINARY_DIR
if it's still being used to avoid modifying the source tree.
prtest:full
Try to avoid dealing with cmake configuration/platforms/etc.
The remaining 2 build failures were pretty simple tweaks, so I went ahead and made them. The CI is passing now, and I confirmed that it still works when referenced from a rust crate. There was a network failure int he build, but I rebased to trigger a test rerun. Do you think this is good to merge in its latest state? |
@@ -345,6 +345,9 @@ semver = { version = "1.0.17", default-features = false } | |||
# in configuring binary size and or exploring the binary size implications of | |||
# various features. Most features are enabled by default but most embeddings | |||
# likely won't need all features. | |||
# | |||
# When adding or removing a feature, make sure to kepe the C API in sync by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# When adding or removing a feature, make sure to kepe the C API in sync by | |
# When adding or removing a feature, make sure to keep the C API in sync by |
@@ -11,22 +11,22 @@ | |||
* are three mechanisms for yielding control from wasm to the caller: fuel, | |||
* epochs, and async host functions. | |||
* | |||
* When WebAssembly is executed, a #wasmtime_call_future_t is returned. This | |||
* When WebAssembly is executed, a `wasmtime_call_future_t` is returned. This |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this was necessary at one stage of testing to appease doxygen. That being said I barely understanding doxygen and we could very well be holding doxygen wrong where this should work when it doesn't.
@@ -22,6 +23,8 @@ | |||
#cmakedefine WASMTIME_FEATURE_ASYNC | |||
#cmakedefine WASMTIME_FEATURE_CRANELIFT | |||
#cmakedefine WASMTIME_FEATURE_WINCH | |||
// ... if you add a line above this be sure to change the other locations | |||
// marked WASMTIME_FEATURE_LIST |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you move this comment above the list (here and elsewhere), then you can avoid the duplicate nonce (less noise when grep
ping).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I like having this at the end because features are often added at the end and a comment only at the top might get missed. The amount of duplication here though is unfortunate across the codebase but that would probably be best fixed with a "tidy" script or something like that rather than relying on us humans to handle everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just mean as a trivial way to halve the number of hits: no need to have the nonce both before and after the list; once is enough (no matter where).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thanks for debugging that! This looks good to me yeah, so I'm going to go ahead and merge. I'm going to follow up with some responses to @clason as well and there can always be follow-ups too to handle things.
And also backport (24.0 is probably good enough) ;) |
I'd definitely love to get this in 24, and 23 would be nice if possible. Link to @clason's backport PRs: |
* Use cmake to build wasmtime-c-api * Properly expose features when building via cmake * Install all headers to same directory * Add vets * attempt to fix ci * Run all tests on CI prtest:full * Set CARGO_BUILD_TARGET; add CMakeLists to package * Update comment on github action * Attempt to fix android build * Fix source dir modifications of c-api build * Re-add BINARY_DIR option * Fix build * Move header installation to a cmake script Try to avoid dealing with cmake configuration/platforms/etc. * Tweak build of headers * Install headers in build dir for examples * Add cmake files to dist, fix header install dir --------- Co-authored-by: Ryan Patterson <cgamesplay@cgamesplay.com> Co-authored-by: Alex Crichton <alex@alexcrichton.com>
* Use cmake to build wasmtime-c-api * Properly expose features when building via cmake * Install all headers to same directory * Add vets * attempt to fix ci * Run all tests on CI prtest:full * Set CARGO_BUILD_TARGET; add CMakeLists to package * Update comment on github action * Attempt to fix android build * Fix source dir modifications of c-api build * Re-add BINARY_DIR option * Fix build * Move header installation to a cmake script Try to avoid dealing with cmake configuration/platforms/etc. * Tweak build of headers * Install headers in build dir for examples * Add cmake files to dist, fix header install dir --------- Co-authored-by: Ryan Patterson <cgamesplay@cgamesplay.com> Co-authored-by: Alex Crichton <alex@alexcrichton.com>
This resolves #8890, and allows a rust project to use the
wasmtime-c-api
crate again.In #8642, the build process was changed but the rust build script was not changed to match. In addition, because the CMake configuration invokes cargo, it isn't possible for cargo to then invoke CMake (cylic dependency). To resolve this, we introduce a new CMake target that only produces the necessary files for the build to succeed, and then allow cargo to build the API as normal.
I've tested that this works in my local copy of tree-sitter, which depends on the
wasmtime-c-api-impl
crate.