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

Fix rules_rust target selection #31

Open
martijneken opened this issue Nov 16, 2023 · 3 comments
Open

Fix rules_rust target selection #31

martijneken opened this issue Nov 16, 2023 · 3 comments

Comments

@martijneken
Copy link
Collaborator

Actual Behavior

$ CARGO_BAZEL_REPIN=1 bazelisk build //samples/example:plugin_rust.wasm
ERROR: Target //samples/example:plugin_rust.wasm is incompatible and cannot be built, but was explicitly requested.
Dependency chain:
    //samples/example:plugin_rust.wasm
    //samples/example:_wasm_plugin_rust_wasm
    @crate_index//:hmac
    @crate_index__hmac-0.12.1//:hmac
    @crate_index__digest-0.10.7//:digest
    @crate_index__block-buffer-0.10.4//:block_buffer
    @crate_index__generic-array-0.14.7//:generic_array
    @crate_index__generic-array-0.14.7//:build_script_build
    @crate_index__generic-array-0.14.7//:generic-array_build_script
    @crate_index__version_check-0.9.4//:version_check   <-- target platform (@local_config_platform//:host) didn't satisfy constraint @platforms//:incompatible

All the generated Cargo targets have the same problem:

    target_compatible_with = select({
        "@rules_rust//rust/platform:wasm32-wasi": [],
        "//conditions:default": ["@platforms//:incompatible"],
    }),

Somehow we are not setting target platform correctly? We should be, via this rust_binary transition:
https://github.com/proxy-wasm/proxy-wasm-cpp-host/blob/master/bazel/wasm.bzl

Steps to Reproduce the Problem

  1. Update proxy-wasm-cpp-host, which picks up feature: target_compatible_with added to CommonAttrs bazelbuild/rules_rust#1976
  2. Build a Rust plugin, see build error

Workaround: set generate_target_compatible_with = False

@martijneken
Copy link
Collaborator Author

martijneken commented Nov 16, 2023

Somehow we are not setting target platform correctly? We should be, via this rust_binary transition

This might be the crux of the issue. Because we're using the ProxyWasm transition for rust_binary targets, perhaps the overall build (and thus crates_repository) does not have a wasm platform set.

Then again, providing the platform at the command line does not fix this:
bazelisk build --platforms="@rules_rust//rust/platform:wasi" //...

And the transition explicitly sets the platform:
https://github.com/proxy-wasm/proxy-wasm-cpp-host/blob/9be9637b5d595483ddba218eb09879818a5e0ffc/bazel/wasm.bzl#L22-L25

@martijneken
Copy link
Collaborator Author

Workaround applied in #36

@martijneken
Copy link
Collaborator Author

martijneken commented Feb 12, 2024

I bet the wasi_rust_binary_rule would work (it explicitly gets a platform attribute in the transition), but the rust_binary() rule here does not have a platform set (hence target platform @local_config_platform//:host)

@martijneken martijneken changed the title Recent rules_rust (via proxy-wasm-cpp-host) breaks Rust plugin compilation Fix rules_rust target selection Jan 8, 2025
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

No branches or pull requests

1 participant