Skip to content

fix: Revert optional feature syntax - #421

Closed
KeyWeeUsr wants to merge 1 commit into
rust-cli:mainfrom
KeyWeeUsr:fix-vendoring
Closed

KeyWeeUsr wants to merge 1 commit into
rust-cli:mainfrom
KeyWeeUsr:fix-vendoring

Conversation

@KeyWeeUsr

Copy link
Copy Markdown

Hey 👋

I read the guide but I'm not sure whether this revert would justify creating a separate issue, so I made a PR instead. Feel free to close/convert if needed.

What does this PR try to solve?

I'm experiencing an issue when vendoring caused by 132fe86 (package-name?/feature specifically). I'm not sure whether this is a bug in Cargo potentially opened elsewhere, however I reverted the problematic parts locally this way. The commit also contains a POC which might also be useful as a CI test for vendoring in case such change happens again in the future, so it's caught before releasing.

POC below:

FROM rust:alpine
WORKDIR /tmp

RUN apk add git
RUN git clone --depth=1 https://github.com/rust-lang/log vendor/log
RUN git clone --depth=1 https://github.com/rust-cli/env_logger vendor/env_logger

RUN <<EOR
cat<<EOF > vendor/env_logger/fix.patch
diff --git a/crates/env_filter/Cargo.toml b/crates/env_filter/Cargo.toml
--- a/crates/env_filter/Cargo.toml
+++ b/crates/env_filter/Cargo.toml
@@ -28,11 +28,11 @@ pre-release-replacements = [
 [features]
 default = ["std", "regex"]
 regex = ["dep:regex"]
-std = ["log/std", "regex?/std"]
+std = ["log/std"]

 [dependencies]
 log = { version = "0.4.29" }
-regex = { version = "1.12.3", optional = true, default-features=false, features=["perf"] }
+regex = { version = "1.12.3", optional = true, default-features=false, features=["std", "perf"] }

 [dev-dependencies]
 snapbox = "1.0"
EOF

cd vendor/env_logger&&git apply fix.patch
EOR

RUN cat vendor/env_logger/crates/env_filter/Cargo.toml
RUN <<EOR
mkdir src
echo "fn main() {}" > src/main.rs

cat<<EOF > Cargo.toml
[package]
name = "bug"
edition = "2024"

[dependencies]
env_logger = { version = "0.11.11", default-features = false, features = [] }
log = { version = "0.4.34", default-features = false }
# note: happens even if not specified here
env_filter = { version = "2.0.0", default-features = false, features = [] }

[patch.crates-io]
env_logger = { path = "vendor/env_logger" }
env_filter = { path = "vendor/env_logger/crates/env_filter" }
log = { path = "vendor/log" }
EOF
EOR

RUN <<EOR
rustc --version
cargo --version
cargo build --offline --no-default-features --verbose
EOR

Notes to reviewers

POC above and in the commit message.
LLM involvement: Zero

The optional feature syntax (`package-name?/feature`) doesn't seem to work
properly while vendoring a (sub-)dependency.

POC below:

    FROM rust:alpine
    WORKDIR /tmp

    RUN apk add git
    RUN git clone --depth=1 https://github.com/rust-lang/log vendor/log
    RUN git clone --depth=1 https://github.com/rust-cli/env_logger vendor/env_logger

    RUN <<EOR
    cat<<EOF > vendor/env_logger/fix.patch
    diff --git a/crates/env_filter/Cargo.toml b/crates/env_filter/Cargo.toml
    --- a/crates/env_filter/Cargo.toml
    +++ b/crates/env_filter/Cargo.toml
    @@ -28,11 +28,11 @@ pre-release-replacements = [
     [features]
     default = ["std", "regex"]
     regex = ["dep:regex"]
    -std = ["log/std", "regex?/std"]
    +std = ["log/std"]

     [dependencies]
     log = { version = "0.4.29" }
    -regex = { version = "1.12.3", optional = true, default-features=false, features=["perf"] }
    +regex = { version = "1.12.3", optional = true, default-features=false, features=["std", "perf"] }

     [dev-dependencies]
     snapbox = "1.0"
    EOF

    cd vendor/env_logger&&git apply fix.patch
    EOR

    RUN cat vendor/env_logger/crates/env_filter/Cargo.toml
    RUN <<EOR
    mkdir src
    echo "fn main() {}" > src/main.rs

    cat<<EOF > Cargo.toml
    [package]
    name = "bug"
    edition = "2024"

    [dependencies]
    env_logger = { version = "0.11.11", default-features = false, features = [] }
    log = { version = "0.4.34", default-features = false }
    # note: happens even if not specified here
    env_filter = { version = "2.0.0", default-features = false, features = [] }

    [patch.crates-io]
    env_logger = { path = "vendor/env_logger" }
    env_filter = { path = "vendor/env_logger/crates/env_filter" }
    log = { path = "vendor/log" }
    EOF
    EOR

    RUN <<EOR
    rustc --version
    cargo --version
    cargo build --offline --no-default-features --verbose
    EOR
@epage

epage commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

I can't imagine what this would be the root cause for, rather than a workaround. I'd prefer to focus on the root cause. The only vendor issue I'm aware of is rust-lang/cargo#10801.

Going to close this in favor of whereever the root cause Issue is opened.

Note that If reverting somethìng, then likely this isn' t so straightforward that you can skip an issue. An Issue would have better encouraged describing the problem, more than the PR template does.

@epage epage closed this Sep 14, 2026
@KeyWeeUsr

Copy link
Copy Markdown
Author

@epage I believe that's the bug I'm experiencing! Thanks

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.

2 participants