microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.29k stars 480 forks source link

windows-bindgen inserts duplicated features entry into cargo.toml if run repeatedly #2931

Closed youyuanwu closed 5 months ago

youyuanwu commented 5 months ago

Summary

The first time executing windows-bindgen::bindgen creates the feature switches correctly in the cargo.toml:

[features]
implement = []
Win32_Foundation = []
ServiceFabric = []
ServiceFabric_FabricCommon = ["ServiceFabric"]
ServiceFabric_FabricCommon_FabricClient = ["ServiceFabric_FabricCommon"]
ServiceFabric_FabricCommon_FabricRuntime = ["ServiceFabric_FabricCommon"]
ServiceFabric_FabricCommon_FabricTransport = ["ServiceFabric_FabricCommon"]

If I run the bindgen again the feature switches are inserted again and the crate cannot compile:

[features]
implement = []
Foundation = []
Win32_Foundation = []
ServiceFabric = ["Foundation"]
ServiceFabric_FabricCommon = ["ServiceFabric"]
ServiceFabric_FabricCommon_FabricClient = ["ServiceFabric_FabricCommon"]
ServiceFabric_FabricCommon_FabricRuntime = ["ServiceFabric_FabricCommon"]
ServiceFabric_FabricCommon_FabricTransport = ["ServiceFabric_FabricCommon"]
ServiceFabric = ["Foundation"]
ServiceFabric_FabricCommon = ["ServiceFabric"]
ServiceFabric_FabricCommon_FabricClient = ["ServiceFabric_FabricCommon"]
ServiceFabric_FabricCommon_FabricRuntime = ["ServiceFabric_FabricCommon"]
ServiceFabric_FabricCommon_FabricTransport = ["ServiceFabric_FabricCommon"]

The bindgen tool should detect if the features are already present on the toml and only append missing ones. This is annoying in code regeneration and manual editing of the toml is required.

To reproduce, run the tools_api target in this repo: https://github.com/Azure/service-fabric-rs This issue is originally found in v0.51 and still present in v0.54

Crate manifest

No response

Crate code

No response

kennykerr commented 5 months ago

That's what this line is for:

https://github.com/microsoft/windows-rs/blob/d9cc52e2a22c08aa0bda3e407b463e07a48a6137/crates/libs/sys/Cargo.toml#L29

Anything prior to this will be preserved. Anything after this line will be replaced.

youyuanwu commented 5 months ago

Thanks for point that out. Adding the comment resolves this issue.