Skip to content

Commit fa5759c

Browse files
NathanSWardabonander
authored andcommittedFeb 14, 2023
Use platform specific path separators
Problem: - When `include!(..)`ing the `mime_types_generated` file, it was assumed that the separator was `/`. However, this will occasionally break on windows causing a compile error. Solution - From the build script, embed the file path into a compile-time `env!` which uses the correct path separator.
1 parent 21415be commit fa5759c

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed
 

‎build.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ const PHF_PATH: &str = "::impl_::phf";
2323
fn main() {
2424
let out_dir = env::var("OUT_DIR").unwrap();
2525
let dest_path = Path::new(&out_dir).join("mime_types_generated.rs");
26-
let mut outfile = BufWriter::new(File::create(dest_path).unwrap());
26+
let mut outfile = BufWriter::new(File::create(&dest_path).unwrap());
27+
28+
println!(
29+
"cargo:rustc-env=MIME_TYPES_GENERATED_PATH={}",
30+
dest_path.display()
31+
);
2732

2833
#[cfg(feature = "phf")]
2934
build_forward_map(&mut outfile);

‎src/impl_bin_search.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use unicase::UniCase;
22

33
include!("mime_types.rs");
4-
include!(concat!(env!("OUT_DIR"), "/mime_types_generated.rs"));
4+
include!(env!("MIME_TYPES_GENERATED_PATH"));
55

66
#[cfg(feature = "rev-mappings")]
77
#[derive(Copy, Clone)]

‎src/impl_phf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate phf;
22

33
use unicase::UniCase;
44

5-
include!(concat!(env!("OUT_DIR"), "/mime_types_generated.rs"));
5+
include!(env!("MIME_TYPES_GENERATED_PATH"));
66

77
#[cfg(feature = "rev-mappings")]
88
struct TopLevelExts {

0 commit comments

Comments
 (0)
Please sign in to comment.