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

build: one cargo workspace for the repo #133

Merged
merged 22 commits into from
Dec 20, 2024
Merged

build: one cargo workspace for the repo #133

merged 22 commits into from
Dec 20, 2024

Conversation

mattyg
Copy link
Member

@mattyg mattyg commented Dec 19, 2024

Resolves #124

@@ -51,6 +51,7 @@ where
/// - Deserialize whatever bytes we can import from the host after calling the host function
/// - Return a `Result` of the deserialized output type `O`
#[inline(always)]
#[allow(improper_ctypes_definitions)]
pub fn host_call<I, O>(
f: unsafe extern "C" fn(usize, usize) -> DoubleUSize,
Copy link
Member Author

Choose a reason for hiding this comment

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

This gives a warning that u128 is not an ffi safe interface. Since our CI requires that clippy passes with no warnings, this became blocking.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah this is a funny one. It's helpful to allow 32-bit or 64-bit builds but it would be invalid with u128. I'm not aware of a type that include the first two but not the other. Reasonable to ignore I think

@@ -159,26 +160,3 @@ macro_rules! try_ptr {
}
}};
}

#[cfg(test)]
pub mod tests {
Copy link
Member Author

@mattyg mattyg Dec 19, 2024

Choose a reason for hiding this comment

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

These tests were never being run.

If they are worth keeping, should they be moved into the host crate and only run when the feature flag error_as_host is not enabled? I don't totally understand the utility since it seems like we always have error_as_host enabled.

Copy link
Member

Choose a reason for hiding this comment

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

The tests seem reasonable enough to me, I probably would try to keep them.

If we always use the feature flag though, I don't see a reason not to remove that?

Copy link
Member Author

@mattyg mattyg Dec 20, 2024

Choose a reason for hiding this comment

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

Ah okay I was confused. This is about the default behavior of passing a string into wasm_error!().

By default this will produce a WasmErrorInner::Guest("my error"), in hdi it follows this behavior. When the error_as_host feature is enabled, it will produce a WasmErrorInner:Host("my error"), in holochain and holochain_wasmer_host it follows this behavior.

Because the wasm_error!() is defined in crates/common, I moved both this test and the mirroring test (in crates/host/src/guest.rs) into crates/common/src/result.rs. I put each test behind the feature flags required for their behavior. Let me know if that looks good.

@@ -6,18 +6,14 @@ export WASMER_BACKTRACE=1

# static tests
cargo fmt --check
( cd test && cargo fmt --check )
( cd crates/guest && cargo fmt --check )
Copy link
Member Author

@mattyg mattyg Dec 19, 2024

Choose a reason for hiding this comment

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

crates/guest and test are now in the root workspace, so no need to check separately

cargo clippy -- --deny warnings
( cd test && cargo clippy -- --deny warnings )
Copy link
Member Author

Choose a reason for hiding this comment

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

test is now in the root workspace

cargo test --no-default-features --features error_as_host,wasmer_sys_prod ${1-} -- --nocapture

# test that everything builds
cargo build --release --manifest-path test/test_wasm/Cargo.toml --target wasm32-unknown-unknown
Copy link
Member Author

Choose a reason for hiding this comment

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

I think these are redundant -- we don't need to run them for each feature flag.

@@ -34,9 +34,6 @@ name = "test"
crate-type = ["cdylib", "rlib"]
path = "src/test.rs"

[profile.release]
debug = true
Copy link
Member Author

@mattyg mattyg Dec 19, 2024

Choose a reason for hiding this comment

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

Moved to the workspace-level cargo.toml so it is actually applied

@@ -372,48 +372,3 @@ impl ModuleCache {
Ok(module)
}
}

#[cfg(test)]
mod tests {
Copy link
Member Author

@mattyg mattyg Dec 19, 2024

Choose a reason for hiding this comment

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

moved these into crates/host/src/module/wasmer_sys.rs to avoid the clippy warning "warning: private item shadows public glob re-export". I don't totally understand it.

Copy link
Member

Choose a reason for hiding this comment

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

Some naming clash with a pub use a_module::*. We had masses of these in Holochain at some point with the endless re-exports for "convenience" that ended up causing headaches with where types actually lived. This seems fine here

@mattyg mattyg marked this pull request as ready for review December 19, 2024 00:47
Copy link
Member Author

@mattyg mattyg Dec 19, 2024

Choose a reason for hiding this comment

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

Renamed test_wasm to wasm_core to use the same directory and crate naming schema as the other wasm crates. Intended to clarify that this is an example wasm that is used in tests, not actually tests.

@@ -391,7 +391,7 @@ pub mod tests {
match err {
Err(runtime_error) => assert_eq!(
WasmError {
file: "src/wasm.rs".into(),
file: "test-crates/wasm_core/src/wasm.rs".into(),
Copy link
Member Author

Choose a reason for hiding this comment

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

Different file path since this is part of the root workspace now.

test-crates/tests/build.rs Outdated Show resolved Hide resolved
Copy link
Member Author

Choose a reason for hiding this comment

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

All formatting changes

Copy link
Member Author

Choose a reason for hiding this comment

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

All formatting changes

Copy link
Member Author

Choose a reason for hiding this comment

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

All formatting changes

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not being used.

// i.e. "test-crates\\wasm_core\\src/wasm.rs"
//
// To remedy this we normalize the formatting here.
file: file!().replace('\\', "/").to_string(),
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only issue I found noting this: rust-lang/libs-team#503

Alternatively we could just keep the inconsistent path formatting. Or I could use a real "path canonicalization" lib instead of a replace().

@mattyg mattyg requested a review from a team December 20, 2024 00:18
Copy link
Member

@ThetaSinner ThetaSinner left a comment

Choose a reason for hiding this comment

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

This is great! Genuinely wasn't sure it would work out going this far with the change, but it looks like it's come out really nicely.

I'm going to check this out and give it a look just to make sure it looks like it does in my head after the review but really just a couple of minor comments :)

@ThetaSinner
Copy link
Member

Yeah looks great locally!

Possible the test-creates doesn't need to be flat? The tests and common crates could be directly under test-crates then the wasm_* could go into a wasm directory instead of having name prefixes. But that really would be fiddling about :D Just a thought, not a request

@mattyg mattyg requested a review from ThetaSinner December 20, 2024 18:19
Copy link
Member

@ThetaSinner ThetaSinner left a comment

Choose a reason for hiding this comment

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

Really nice! Thank you taking this on :)

Copy link
Contributor

@jost-s jost-s left a comment

Choose a reason for hiding this comment

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

Awesome! ❤️

@mattyg mattyg merged commit d136c6c into main Dec 20, 2024
13 checks passed
@mattyg mattyg deleted the chore/one-workspace branch December 20, 2024 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use one workspace
3 participants