1- use std:: { env, fs} ;
1+ use std:: { collections :: BTreeSet , env, fs} ;
22
33use crate :: { CRATE_NAME_FILE , FEATURES_FILE } ;
44
@@ -62,21 +62,16 @@ pub fn init_prebindgen_out_dir() {
6262 ) ;
6363 } ) ;
6464
65- // Collect enabled Cargo features from environment and store them
66- // Cargo exposes enabled features to build.rs as env vars CARGO_FEATURE_<NAME>
67- // where <NAME> is uppercased and '-' replaced with '_'. Here we convert back.
6865 let features = get_features ( ) ;
6966
7067 // Save features list to features.txt (one per line)
7168 let features_path = prebindgen_dir. join ( FEATURES_FILE ) ;
72- let features_contents = if features. is_empty ( ) {
73- String :: new ( )
74- } else {
75- let mut s = features. join ( "\n " ) ;
76- s. push ( '\n' ) ;
77- s
78- } ;
79- fs:: write ( & features_path, features_contents) . unwrap_or_else ( |e| {
69+ let mut feature_contents = String :: new ( ) ;
70+ for feature in & features {
71+ feature_contents += feature;
72+ feature_contents. push ( '\n' ) ;
73+ }
74+ fs:: write ( & features_path, feature_contents) . unwrap_or_else ( |e| {
8075 panic ! (
8176 "Failed to write features to {}: {}" ,
8277 features_path. display( ) ,
@@ -97,21 +92,20 @@ pub fn init_prebindgen_out_dir() {
9792 ) ;
9893}
9994
100- /// Return list of enabled Cargo features in build.rs
101- pub fn get_features ( ) -> Vec < String > {
95+ /// Collect enabled Cargo features from environment and store them
96+ /// Cargo exposes enabled features to build.rs as env vars CARGO_FEATURE_<NAME>
97+ /// where <NAME> is uppercased and '-' replaced with '_'. Here we convert back.
98+ pub fn get_features ( ) -> BTreeSet < String > {
10299 env:: var ( "OUT_DIR" ) . expect (
103100 "OUT_DIR environment variable not set. This function should be called from build.rs." ,
104101 ) ;
105- let mut features : Vec < String > = std:: env:: vars ( )
102+ std:: env:: vars ( )
106103 . filter_map ( |( k, _) | {
107104 k. strip_prefix ( "CARGO_FEATURE_" )
108105 . map ( |name| name. to_string ( ) )
109106 } )
110107 . map ( |name| name. to_lowercase ( ) . replace ( '_' , "-" ) )
111- . collect ( ) ;
112- features. sort ( ) ;
113- features. dedup ( ) ;
114- features
108+ . collect ( )
115109}
116110
117111/// Name of the prebindgen output directory
0 commit comments