Skip to content

Commit dfb1903

Browse files
committed
Get WASI working?
1 parent 5c40dc8 commit dfb1903

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

Makefile.pre.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3379,7 +3379,7 @@ Python/thread.o: @THREADHEADERS@ $(srcdir)/Python/condvar.h
33793379
# Module dependencies and platform-specific files
33803380

33813381
cpython-sys: Modules/cpython-sys/Cargo.toml Modules/cpython-sys/build.rs Modules/cpython-sys/wrapper.h Modules/cpython-sys/parser.h
3382-
CARGO_TARGET_DIR=$(abs_builddir)/target PYTHON_BUILD_DIR=$(abs_builddir) PY_CC="$(CC)" PY_CPPFLAGS="$(CPPFLAGS)" LLVM_TARGET="$(LLVM_TARGET)" $(CARGO_HOME)/bin/cargo build --lib --locked --package cpython-sys --profile $(CARGO_PROFILE) $(if $(CARGO_TARGET),--target=$(CARGO_TARGET)) --manifest-path $(srcdir)/Cargo.toml
3382+
CARGO_TARGET_DIR=$(abs_builddir)/target PYTHON_BUILD_DIR=$(abs_builddir) PY_CC="$(CC)" PY_CPPFLAGS="$(CPPFLAGS)" PY_CFLAGS="$(CFLAGS)" LLVM_TARGET="$(LLVM_TARGET)" $(CARGO_HOME)/bin/cargo build --lib --locked --package cpython-sys --profile $(CARGO_PROFILE) $(if $(CARGO_TARGET),--target=$(CARGO_TARGET)) --manifest-path $(srcdir)/Cargo.toml
33833383

33843384
RUST_STATICLIB_A= target/$(if $(CARGO_TARGET),$(CARGO_TARGET)/$(CARGO_TARGET_DIR),$(CARGO_TARGET_DIR))/libcpython_rust_staticlib.a
33853385

Modules/Setup.stdlib.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
############################################################################
121121
# Rust modules
122122
#
123-
@MODULE__BASE64_TRUE@_base64 _base64/Cargo.toml _base64/src/lib.rs lib_base64.a
123+
@MODULE__BASE64_TRUE@_base64 _base64/Cargo.toml _base64/src/lib.rs
124124

125125
############################################################################
126126
# Modules with some UNIX dependencies

Modules/cpython-sys/build.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ fn generate_c_api_bindings(srcdir: &Path, builddir: Option<&str>, out_path: &Pat
5151
builder = builder.clang_arg(format!("--target={}", target));
5252
}
5353

54-
// Extract cross-compilation flags from the C compiler command (PY_CC)
55-
// and preprocessor flags (PY_CPPFLAGS). These provide the sysroot and
56-
// include paths that bindgen's clang needs to find system headers when
57-
// cross-compiling.
54+
// Extract cross-compilation flags from the C compiler command (PY_CC),
55+
// preprocessor flags (PY_CPPFLAGS), and compiler flags (PY_CFLAGS).
56+
// These provide the sysroot, include paths, and defines that bindgen's
57+
// clang needs when cross-compiling.
5858
//
59-
// - WASI: the sysroot is embedded in CC ("clang --sysroot=...")
60-
// - iOS: -isysroot in CPPFLAGS points to the SDK
59+
// - WASI: sysroot in CC, -D_WASI_EMULATED_SIGNAL in CFLAGS
60+
// - iOS: -isysroot in CPPFLAGS
6161
let mut have_sysroot = false;
62-
for env_name in ["PY_CC", "PY_CPPFLAGS"] {
62+
for env_name in ["PY_CC", "PY_CPPFLAGS", "PY_CFLAGS"] {
6363
if let Ok(value) = env::var(env_name) {
6464
if let Some(flags) = shlex::split(&value) {
6565
let mut iter = flags.iter().peekable();
@@ -126,13 +126,15 @@ fn generate_c_api_bindings(srcdir: &Path, builddir: Option<&str>, out_path: &Pat
126126
}
127127
}
128128

129-
// Always search the source dir and the public headers.
130-
let mut include_dirs = vec![srcdir.to_path_buf(), srcdir.join("Include")];
131-
// Include the build directory if provided; out-of-tree builds place
132-
// the generated pyconfig.h there.
129+
// Include the build directory first so that cross-build pyconfig.h
130+
// takes precedence over any pyconfig.h in the source tree (which may
131+
// be from a native build with different settings like LONG_BIT).
132+
let mut include_dirs = Vec::new();
133133
if let Some(build) = builddir {
134134
include_dirs.push(PathBuf::from(build));
135135
}
136+
include_dirs.push(srcdir.to_path_buf());
137+
include_dirs.push(srcdir.join("Include"));
136138

137139
for dir in include_dirs {
138140
builder = builder.clang_arg(format!("-I{}", dir.display()));

0 commit comments

Comments
 (0)