Skip to content

fix: use forward slash in include paths for cross-compilation support#7

Open
forrestsmithfb wants to merge 1 commit intottys3:mainfrom
forrestsmithfb:fix/cross-compile-path-separator
Open

fix: use forward slash in include paths for cross-compilation support#7
forrestsmithfb wants to merge 1 commit intottys3:mainfrom
forrestsmithfb:fix/cross-compile-path-separator

Conversation

@forrestsmithfb
Copy link

Summary

Replace the MIME_TYPES_GENERATED_PATH environment variable with a direct concat!(env!("OUT_DIR"), "/mime_types_generated.rs").

The previous approach used path::MAIN_SEPARATOR in build.rs to construct the env var value. Since build.rs runs on the host, MAIN_SEPARATOR reflects the host's path convention, not the target's. For example, when cross-compiling on a Windows host for a Linux target, the env var would contain a backslash (e.g. \mime_types_generated.rs), producing an invalid path when concatenated with OUT_DIR on the target. Using a literal forward slash avoids this, as forward slashes are accepted in include! paths on all platforms.

Changes

  • build.rs: Remove the cargo:rustc-env=MIME_TYPES_GENERATED_PATH println and the now-unused path import
  • src/impl_bin_search.rs: Replace include!(concat!(env!("OUT_DIR"), env!("MIME_TYPES_GENERATED_PATH"))) with include!(concat!(env!("OUT_DIR"), "/mime_types_generated.rs"))
  • src/impl_phf.rs: Same replacement

Test plan

  • cargo build passes
  • cargo test passes (all 7 unit tests)

Replace the MIME_TYPES_GENERATED_PATH environment variable with a direct
concat!(env!("OUT_DIR"), "/mime_types_generated.rs").

The previous approach used path::MAIN_SEPARATOR in build.rs to construct
the env var value. Since build.rs runs on the host, MAIN_SEPARATOR
reflects the host's path convention, not the target's. For example, when
cross-compiling on a Windows host for a Linux target, the env var would
contain a backslash (e.g. "\mime_types_generated.rs"), producing an
invalid path when concatenated with OUT_DIR on the target. Using a
literal forward slash avoids this, as forward slashes are accepted in
include! paths on all platforms.
@qodo-free-for-open-source-projects

Review Summary by Qodo

Fix cross-compilation by using forward slash in include paths

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fix cross-compilation path separator issue in include! macros
• Replace environment variable with hardcoded forward slash path
• Remove unused path::MAIN_SEPARATOR from build script
• Ensure forward slash works on all platforms for include! paths
Diagram
flowchart LR
  A["build.rs<br/>path::MAIN_SEPARATOR"] -->|"Remove env var<br/>construction"| B["Hardcoded forward slash"]
  C["impl_bin_search.rs<br/>env!MIME_TYPES_GENERATED_PATH"] -->|"Replace with<br/>literal path"| B
  D["impl_phf.rs<br/>env!MIME_TYPES_GENERATED_PATH"] -->|"Replace with<br/>literal path"| B
  B -->|"Works on all<br/>platforms"| E["Cross-compilation<br/>support"]
Loading

Grey Divider

File Changes

1. build.rs 🐞 Bug fix +1/-7

Remove environment variable path construction

• Remove path::MAIN_SEPARATOR import as it is no longer needed
• Delete cargo:rustc-env=MIME_TYPES_GENERATED_PATH println statement that constructed path with
 host-specific separator
• Simplify path import to only use Path type

build.rs


2. src/impl_bin_search.rs 🐞 Bug fix +1/-1

Replace environment variable with literal path

• Replace include!(concat!(env!("OUT_DIR"), env!("MIME_TYPES_GENERATED_PATH"))) with hardcoded
 forward slash path
• Use include!(concat!(env!("OUT_DIR"), "/mime_types_generated.rs")) directly

src/impl_bin_search.rs


3. src/impl_phf.rs 🐞 Bug fix +1/-1

Replace environment variable with literal path

• Replace include!(concat!(env!("OUT_DIR"), env!("MIME_TYPES_GENERATED_PATH"))) with hardcoded
 forward slash path
• Use include!(concat!(env!("OUT_DIR"), "/mime_types_generated.rs")) directly

src/impl_phf.rs


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link

qodo-free-for-open-source-projects bot commented Mar 1, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Remediation recommended

1. Hardcoded OUT_DIR join 🐞 Bug ⛯ Reliability
Description
The generated-file include path is now duplicated and manually joined using a literal
"/mime_types_generated.rs" in multiple modules, while build.rs writes the file using Path::join.
This inconsistent path construction and duplicated filename increases the chance of
platform-specific include! path failures and future rename drift.
Code

src/impl_bin_search.rs[4]

+include!(concat!(env!("OUT_DIR"), "/mime_types_generated.rs"));
Evidence
Both implementations now hardcode the generated filename and a forward-slash join in include!(), but
build.rs writes the file using std::path::Path::join with the same filename stored separately. This
creates duplication (multiple locations must stay in sync) and mixes path construction styles
(string concat vs Path joining).

src/impl_bin_search.rs[1-5]
src/impl_phf.rs[1-6]
build.rs[20-31]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The generated file path is now hardcoded and duplicated across multiple include! call sites, and it is joined via string concatenation while build.rs writes via Path::join. This increases the risk of platform-specific include! failures and future drift if the filename ever changes.

## Issue Context
`include!` paths must match how the build script writes the file into `OUT_DIR`. Today, build.rs and the include sites construct the path differently and the filename is duplicated.

## Fix Focus Areas
- build.rs[20-31]
- src/impl_bin_search.rs[1-5]
- src/impl_phf.rs[1-6]

## Suggested change
- In `build.rs`, restore a single `cargo:rustc-env` value but set it to a literal forward-slash suffix:
 - `println!(&quot;cargo:rustc-env=MIME_TYPES_GENERATED_PATH=/mime_types_generated.rs&quot;);`
- In both `src/impl_bin_search.rs` and `src/impl_phf.rs`, switch to:
 - `include!(concat!(env!(&quot;OUT_DIR&quot;), env!(&quot;MIME_TYPES_GENERATED_PATH&quot;)));`
This preserves the PR’s intent (forward slash) while removing duplication and keeping one source of truth.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

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.

1 participant