Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/setup-rust-windows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ inputs:
runs:
using: composite
steps:
- uses: dtolnay/rust-toolchain@ab40b01f54fe82bdf65693ea090a1e4942c136e7 # 1.91.1
- uses: dtolnay/rust-toolchain@f133eefe930d61f0d9371efd474daf0125ed3dd1 # 1.95.0
with:
toolchain: 1.91.1
toolchain: 1.95.0
targets: i686-pc-windows-msvc,x86_64-pc-windows-msvc,aarch64-pc-windows-msvc
# LIBCLANG_PATH must be set explicitly so the vcxproj uses the LLVM we
# install here rather than the VS-bundled LLVM whose clang headers have
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ jobs:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@ab40b01f54fe82bdf65693ea090a1e4942c136e7 # 1.91.1
- uses: dtolnay/rust-toolchain@f133eefe930d61f0d9371efd474daf0125ed3dd1 # 1.95.0
with:
toolchain: 1.91.1
toolchain: 1.95.0
targets: ${{ matrix.arch }}-linux-android
- name: Build and test
run: JAVA_HOME="${JAVA_HOME_21_X64:-$JAVA_HOME_21_arm64}" python3 Platforms/Android ci --fast-ci ${{ matrix.arch }}-linux-android
Expand All @@ -370,9 +370,9 @@ jobs:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@ab40b01f54fe82bdf65693ea090a1e4942c136e7 # 1.91.1
- uses: dtolnay/rust-toolchain@f133eefe930d61f0d9371efd474daf0125ed3dd1 # 1.95.0
with:
toolchain: 1.91.1
toolchain: 1.95.0
targets: aarch64-apple-ios-sim
# GitHub recommends explicitly selecting the desired Xcode version:
# https://github.com/actions/runner-images/issues/12541#issuecomment-3083850140
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/reusable-wasi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ jobs:
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.x'
- uses: dtolnay/rust-toolchain@ab40b01f54fe82bdf65693ea090a1e4942c136e7 # 1.91.1
- uses: dtolnay/rust-toolchain@f133eefe930d61f0d9371efd474daf0125ed3dd1 # 1.95.0
with:
toolchain: 1.91.1
toolchain: 1.95.0
targets: wasm32-wasip1
- name: "Runner image version"
run: echo "IMAGE_OS_VERSION=${ImageOS}-${ImageVersion}" >> "$GITHUB_ENV"
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/reusable-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
if: inputs.arch != 'Win32'
run: echo "::add-matcher::.github/problem-matchers/msvc.json"
- name: Build CPython
id: build_cpython
# msvc::musttail is not supported for debug builds, so we have to
# switch to release.
run: >-
Expand All @@ -50,6 +51,20 @@ jobs:
-p "${ARCH}"
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}
shell: bash
- name: Upload Rust linker diagnostics
if: failure() && steps.build_cpython.outcome == 'failure'
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: windows-rust-link-diagnostics-${{ inputs.arch }}-${{ inputs.interpreter }}-${{ inputs.free-threading }}
if-no-files-found: warn
path: |
PCbuild/obj/**/_base64/cargo/**/build/cpython-sys-*/out/c_api.rs
PCbuild/obj/**/_base64/cargo/**/build/*/output
PCbuild/obj/**/_base64/cargo/**/.fingerprint/*/run-build-script-*.json
PCbuild/obj/**/_base64/cargo/**/deps/rustc*/
PCbuild/obj/**/pythoncore/pythoncore.tlog/link.*.tlog
PCbuild/**/python*.dll
PCbuild/**/python*.lib
- name: Display build info
run: .\\python.bat -m test.pythoninfo
- name: Tests
Expand Down
66 changes: 34 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ members = [
"Modules/_base64", "Modules/cpython-build-helper", "Modules/cpython-rust-staticlib",
"Modules/cpython-sys"
]

[workspace.package]
# Make sure to also update the Rust toolchains in GitHub Actions whenever this version is modified
rust-version = "1.95"
1 change: 1 addition & 0 deletions Modules/_base64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "_base64"
version = "0.1.0"
edition = "2024"
rust-version.workspace = true

[dependencies]
cpython-sys ={ path = "../cpython-sys" }
Expand Down
1 change: 1 addition & 0 deletions Modules/cpython-build-helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "cpython-build-helper"
version = "0.1.0"
edition = "2024"
rust-version.workspace = true

[dependencies]
shlex = "1.3"
1 change: 1 addition & 0 deletions Modules/cpython-rust-staticlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "cpython-rust-staticlib"
version = "0.1.0"
edition = "2024"
rust-version.workspace = true

[dependencies]
_base64 ={ path = "../_base64" }
Expand Down
3 changes: 3 additions & 0 deletions Modules/cpython-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
name = "cpython-sys"
version = "0.1.0"
edition = "2024"
rust-version.workspace = true

[dependencies]

[build-dependencies]
bindgen = "0.72.1"
prettyplease = "0.2.37"
shlex = "1.3"
syn = { version = "2.0.110", features = ["full", "parsing"] }
56 changes: 14 additions & 42 deletions Modules/cpython-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,52 +324,24 @@ fn patch_windows_imported_pointer_globals(bindings: String, dll_name: &str) -> S
// The fix: annotate pointer-valued extern statics with `raw-dylib` on
// Windows so Rust generates the import thunk itself and handles the IAT
// indirection correctly — two loads, matching `__declspec(dllimport)`.
let lines: Vec<_> = bindings.lines().collect();
let mut patched = String::with_capacity(bindings.len());
let mut index = 0;

while index < lines.len() {
if lines[index] == "unsafe extern \"C\" {"
&& lines
.get(index + 1)
.and_then(|l| parse_pointer_static_decl(l))
.is_some()
&& lines.get(index + 2).is_some_and(|l| l.trim() == "}")
{
patched.push_str(&format!(
"#[cfg_attr(windows, link(name = \"{dll_name}\", kind = \"raw-dylib\"))]\n"
));
// Keep the original extern block unchanged.
for i in index..index + 3 {
patched.push_str(lines[i]);
patched.push('\n');
}
index += 3;
let mut file = syn::parse_file(&bindings).expect("bindgen emitted invalid Rust");

for item in &mut file.items {
let syn::Item::ForeignMod(foreign_mod) = item else {
continue;
};
let [syn::ForeignItem::Static(static_item)] = foreign_mod.items.as_slice() else {
continue;
};
if !matches!(*static_item.ty, syn::Type::Ptr(_)) {
continue;
}

patched.push_str(lines[index]);
patched.push('\n');
index += 1;
}

patched
}

fn parse_pointer_static_decl(line: &str) -> Option<(&str, bool, &str)> {
let mut decl = line.trim().strip_prefix("pub static ")?;
let is_mut = decl.starts_with("mut ");
if is_mut {
decl = decl.strip_prefix("mut ")?;
}

let (name, ty) = decl.split_once(':')?;
let ty = ty.trim().strip_suffix(';')?;
if !ty.starts_with('*') {
return None;
foreign_mod.attrs.push(syn::parse_quote!(
#[cfg_attr(windows, link(name = #dll_name, kind = "raw-dylib"))]
));
}

Some((name.trim(), is_mut, ty))
prettyplease::unparse(&file)
}

fn add_target_clang_args(
Expand Down
3 changes: 0 additions & 3 deletions rust-toolchain.toml

This file was deleted.

Loading