fix: use forward slash in include paths for cross-compilation support#7
Open
forrestsmithfb wants to merge 1 commit intottys3:mainfrom
Open
fix: use forward slash in include paths for cross-compilation support#7forrestsmithfb wants to merge 1 commit intottys3:mainfrom
forrestsmithfb wants to merge 1 commit intottys3:mainfrom
Conversation
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.
Review Summary by QodoFix cross-compilation by using forward slash in include paths
WalkthroughsDescription• 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 Diagramflowchart 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"]
File Changes1. build.rs
|
Code Review by Qodo
1. Hardcoded OUT_DIR join
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the
MIME_TYPES_GENERATED_PATHenvironment variable with a directconcat!(env!("OUT_DIR"), "/mime_types_generated.rs").The previous approach used
path::MAIN_SEPARATORinbuild.rsto construct the env var value. Sincebuild.rsruns on the host,MAIN_SEPARATORreflects 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 withOUT_DIRon the target. Using a literal forward slash avoids this, as forward slashes are accepted ininclude!paths on all platforms.Changes
build.rs: Remove thecargo:rustc-env=MIME_TYPES_GENERATED_PATHprintln and the now-unusedpathimportsrc/impl_bin_search.rs: Replaceinclude!(concat!(env!("OUT_DIR"), env!("MIME_TYPES_GENERATED_PATH")))withinclude!(concat!(env!("OUT_DIR"), "/mime_types_generated.rs"))src/impl_phf.rs: Same replacementTest plan
cargo buildpassescargo testpasses (all 7 unit tests)