Skip to content

Commit a59b300

Browse files
committed
Run cargo fmt && clippy
1 parent e1936b8 commit a59b300

2 files changed

Lines changed: 40 additions & 51 deletions

File tree

Modules/cpython-build-helper/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ pub fn print_linker_args() {
4040
if let Ok(libpython) = env::var("LIBPYTHON") {
4141
let builddir = env::var("PYTHON_BUILD_DIR").ok();
4242
for arg in shlex::split(&libpython).expect("Invalid LIBPYTHON") {
43-
if arg == "-L." {
44-
if let Some(ref dir) = builddir {
45-
println!("cargo:rustc-cdylib-link-arg=-L{}", dir);
46-
continue;
47-
}
43+
if arg == "-L."
44+
&& let Some(ref dir) = builddir
45+
{
46+
println!("cargo:rustc-cdylib-link-arg=-L{}", dir);
47+
continue;
4848
}
4949
println!("cargo:rustc-cdylib-link-arg={}", arg);
5050
}

Modules/cpython-sys/build.rs

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -60,46 +60,40 @@ fn generate_c_api_bindings(srcdir: &Path, builddir: Option<&str>, out_path: &Pat
6060
// - iOS: -isysroot in CPPFLAGS
6161
let mut have_sysroot = false;
6262
for env_name in ["PY_CC", "PY_CPPFLAGS", "PY_CFLAGS"] {
63-
if let Ok(value) = env::var(env_name) {
64-
if let Some(flags) = shlex::split(&value) {
65-
let mut iter = flags.iter().peekable();
66-
while let Some(flag) = iter.next() {
67-
if flag.starts_with("--sysroot")
68-
|| flag.starts_with("-isysroot")
69-
{
70-
builder = builder.clang_arg(flag);
71-
have_sysroot = true;
72-
// Handle "-isysroot <path>" (space-separated)
73-
if flag == "-isysroot" || flag == "--sysroot" {
74-
if let Some(path) = iter.next() {
75-
builder = builder.clang_arg(path);
76-
}
77-
}
78-
} else if flag.starts_with("-I")
79-
|| flag.starts_with("-D")
80-
|| flag.starts_with("-isystem")
63+
if let Ok(value) = env::var(env_name)
64+
&& let Some(flags) = shlex::split(&value)
65+
{
66+
let mut iter = flags.iter().peekable();
67+
while let Some(flag) = iter.next() {
68+
if flag.starts_with("--sysroot") || flag.starts_with("-isysroot") {
69+
builder = builder.clang_arg(flag);
70+
have_sysroot = true;
71+
// Handle "-isysroot <path>" (space-separated)
72+
if (flag == "-isysroot" || flag == "--sysroot")
73+
&& let Some(path) = iter.next()
8174
{
82-
builder = builder.clang_arg(flag);
75+
builder = builder.clang_arg(path);
8376
}
77+
} else if flag.starts_with("-I")
78+
|| flag.starts_with("-D")
79+
|| flag.starts_with("-isystem")
80+
{
81+
builder = builder.clang_arg(flag);
8482
}
8583
}
8684
}
8785
}
8886

8987
// WASI SDK: WASI_SDK_PATH is set by Tools/wasm/wasi/__main__.py.
9088
// The sysroot is at $WASI_SDK_PATH/share/wasi-sysroot.
91-
if !have_sysroot && target.contains("wasi") {
92-
if let Ok(sdk_path) = env::var("WASI_SDK_PATH") {
93-
let sysroot = PathBuf::from(&sdk_path)
94-
.join("share")
95-
.join("wasi-sysroot");
96-
if sysroot.is_dir() {
97-
builder = builder.clang_arg(format!(
98-
"--sysroot={}",
99-
sysroot.display()
100-
));
101-
have_sysroot = true;
102-
}
89+
if !have_sysroot
90+
&& target.contains("wasi")
91+
&& let Ok(sdk_path) = env::var("WASI_SDK_PATH")
92+
{
93+
let sysroot = PathBuf::from(&sdk_path).join("share").join("wasi-sysroot");
94+
if sysroot.is_dir() {
95+
builder = builder.clang_arg(format!("--sysroot={}", sysroot.display()));
96+
have_sysroot = true;
10397
}
10498
}
10599

@@ -108,21 +102,16 @@ fn generate_c_api_bindings(srcdir: &Path, builddir: Option<&str>, out_path: &Pat
108102
// $ANDROID_HOME/ndk/<ver>/toolchains/llvm/prebuilt/<host>/bin/<triple>-clang
109103
// The sysroot is a sibling of bin/:
110104
// .../toolchains/llvm/prebuilt/<host>/sysroot
111-
if !have_sysroot && target.contains("android") {
112-
if let Ok(cc) = env::var("PY_CC") {
113-
if let Some(parts) = shlex::split(&cc) {
114-
if let Some(binary) = parts.first() {
115-
if let Some(bin_dir) = Path::new(binary).parent() {
116-
let sysroot = bin_dir.with_file_name("sysroot");
117-
if sysroot.is_dir() {
118-
builder = builder.clang_arg(format!(
119-
"--sysroot={}",
120-
sysroot.display()
121-
));
122-
}
123-
}
124-
}
125-
}
105+
if !have_sysroot
106+
&& target.contains("android")
107+
&& let Ok(cc) = env::var("PY_CC")
108+
&& let Some(parts) = shlex::split(&cc)
109+
&& let Some(binary) = parts.first()
110+
&& let Some(bin_dir) = Path::new(binary).parent()
111+
{
112+
let sysroot = bin_dir.with_file_name("sysroot");
113+
if sysroot.is_dir() {
114+
builder = builder.clang_arg(format!("--sysroot={}", sysroot.display()));
126115
}
127116
}
128117

0 commit comments

Comments
 (0)