bazelbuild / rules_rust

Rust rules for Bazel
https://bazelbuild.github.io/rules_rust/
Apache License 2.0
671 stars 434 forks source link

Target OS Arch + Feature Flag Regression #3011

Open ericmcbride opened 2 days ago

ericmcbride commented 2 days ago

We have updated to rules rust 0.54.1 and we are noticing a weird regression with the reqwest library. They added a default feature configuration default = ["default-tls", "charset", "http2", "macos-system-configuration"] for a mac-os specific crate. It takes the following flags

#[cfg(all(target_os = "macos", feature = "macos-system-configuration"))]
use system_configuration::{
    core_foundation::{
        base::CFType,
        dictionary::CFDictionary,
        number::CFNumber,
        string::{CFString, CFStringRef},
    },
    dynamic_store::SCDynamicStoreBuilder,
    sys::schema_definitions::kSCPropNetProxiesHTTPEnable,
    sys::schema_definitions::kSCPropNetProxiesHTTPPort,
    sys::schema_definitions::kSCPropNetProxiesHTTPProxy,
    sys::schema_definitions::kSCPropNetProxiesHTTPSEnable,
    sys::schema_definitions::kSCPropNetProxiesHTTPSPort,
    sys::schema_definitions::kSCPropNetProxiesHTTPSProxy,
};

For some reason on linux x86 and linux-arm64 it s hitting the target_os flag in bazel and it is not doing so with with rules_rust 0.48.0 or with cargo. Any idea why this is happening?

Ive tried using the crate.annotation

 crate.annotation(
    crate = "reqwest",
    version = "0.11.27",
    crate_features = ["default-tls", "charset", "http2"],
    override_target_lib = "@crates_index//:reqwest",
)

But i am getting cyclic deps

    //some-dir:some-bin (cfa282587e9f280b666b5f4aefa7298159ebe1fa690f0b8ef9d34ffeb511b0d4)
    //some-dir:some-bin (cfc81706202ca4f76d7de0ad3ec7512f6faaa459aafda827541c47861f45e386)
    //some-dir:some-bin (cfc81706202ca4f76d7de0ad3ec7512f6faaa459aafda827541c47861f45e386)
    //another-dir:another-bin (cfc81706202ca4f76d7de0ad3ec7512f6faaa459aafda827541c47861f45e386)
.-> @@rules_rust~~crate~crates_index__reqwest-0.11.27//:reqwest (cfc81706202ca4f76d7de0ad3ec7512f6faaa459aafda827541c47861f45e386)
|   @@rules_rust~~crate~crates_index//:reqwest (cfc81706202ca4f76d7de0ad3ec7512f6faaa459aafda827541c47861f45e386)
`-- @@rules_rust~~crate~crates_index__reqwest-0.11.27//:reqwest (cfc81706202ca4f76d7de0ad3ec7512f6faaa459aafda827541c47861f45e386)

Any idea why this could happen? This is stopping us from updating rust.

jgsogo commented 2 days ago

I may have another occurrence of this same issue with rules_rust/0.54.1 (not 100% sure, but it might be worth sharing my scenario here).

In my case it is related to this optional dependency of tauri-plugin-v2.03:

[target."cfg(target_os = \"macos\")".dependencies]
plist = { version = "1", optional = true }

It fails (use of undeclared crate or module plist) when my MODULE.bazel looks like the following:

crate.from_cargo(
    name = "crates_libraries",
    cargo_lockfile = "//:Cargo.lock",
    manifests = [
        "//:Cargo.toml",
        ...
    ],
    supported_platform_triples = [
        # "aarch64-apple-darwin",
        "aarch64-unknown-linux-gnu",
        "x86_64-apple-darwin",
    ],
)

However, it builds successfully when I add the aarch64 platform:

    supported_platform_triples = [
        "aarch64-apple-darwin",
        "aarch64-unknown-linux-gnu",
        "x86_64-apple-darwin",
    ],

I'm using MacOS x86_64.

Note.- I've tried rules_rust/0.53.0 and it also fails.

ericmcbride commented 2 days ago

Sadly this didnt work. Its still trying to build. Im gonna try a crate.select based off platform for features. Not sure what changed that broke this.

ericmcbride commented 1 day ago

Update: Cannot get it to work. Seems like the appropriate cfg(target_os = "macos") aren't working correctly. Not sure if reqwest is the only one. I will add a sample example. Reqwest is a large library and it would suck to see this break all of rules rust