-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix build.rs
: Use env::var_os
to retrieve Path
#1580
Conversation
Is the entire purpose of this PR to support non-Unicode(-compatible) paths? Is there any other goal with this PR? |
I agree with the idea that we should be using |
Yes
Linux filename can be anything that is So the user can use arbitary non-unicode characters in their home dir or whatever dir, Without non-unicode support, this will fail since the So it's possible for these environment variables to contain non-unicode and I'd like ring's |
That is true, but if somebody is taking full advantage of that flexibility, it's really their own fault.
I understand. I'm simply asking could you provide a plausible scenerio where |
On linux, I am able to create a non-unicode dir by running: mkdir $(printf '\xFF') And then cd into it by running: cd $(printf '\xFF') I can create a user with non-unicode home: adduser a --home /home/"$(printf 'a\xFF')" and cd into it: cd /home/"$(printf 'a\xFF')" |
@NobodyXu Is this an issue that's causing trouble on a real system, or just a theoretical issue? |
Unfortunately I don't have any real world example for this, so right now it just stays as a theoretical issue, but I won't be surprised if somebody out there is having non-unicode path in their system, hence I think it's better to support any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build.rs
Outdated
} | ||
|
||
fn main() { | ||
const RING_PREGENERATE_ASM: &str = "RING_PREGENERATE_ASM"; | ||
match read_env_var(RING_PREGENERATE_ASM).as_deref() { | ||
Ok("1") => { | ||
Some(val) if val == OsStr::new("1") => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do Some(val) if val == "1"
; see #1698.
build.rs
Outdated
@@ -692,9 +689,10 @@ fn nasm(file: &Path, arch: &str, include_dir: &Path, out_file: &Path) -> Command | |||
c | |||
} | |||
|
|||
fn run_command_with_args<S>(command_name: S, args: &[String]) | |||
fn run_command_with_args<S, Arg>(command_name: S, args: impl IntoIterator<Item = Arg>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should just get rid of the generics here; see #1698.
Use `env::var_os` instead of `env::var` to handle non utf-8 path correctly. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Do not convert `Path`/`OsStr` to `String` in `cc`, instead creates an `OsString` and push to it. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@briansmith I've rebased this PR against main, please review this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for doing this. If you have other things you want to clean up in build.rs I would be happy to work with you on them. PR #1699 is another one you may be interested in.
target: &Target, | ||
include_dir: &Path, | ||
out_dir: &Path, | ||
) -> PathBuf { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
out_file.to_str().expect("Invalid path") | ||
)) | ||
.arg(file); | ||
let _ = c.arg("-c").arg(arg).arg(file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also very nice.
Codecov Report
@@ Coverage Diff @@
## main #1580 +/- ##
==========================================
- Coverage 95.99% 95.98% -0.01%
==========================================
Files 134 134
Lines 19980 19980
Branches 199 199
==========================================
- Hits 19179 19178 -1
Misses 765 765
- Partials 36 37 +1 see 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Thank you! |
OUT_DIR
inbuild.rs
CARGO_MANIFEST_DIR
: Useenv::var_os
run_command_with_args
to takeOsStr
instead ofString
for argsenv::var_os
inread_env_var
PathBuf
instead ofString
for fncompile
Signed-off-by: Jiahao XU Jiahao_XU@outlook.com