Skip to content

Commit 24bc850

Browse files
committed
Address Sergey's review
1 parent e9ca08f commit 24bc850

4 files changed

Lines changed: 45 additions & 48 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Set up Rust and LLVM for Windows
2+
description: >-
3+
Install the pinned Rust toolchain with Windows cross-compile targets and
4+
a version of LLVM whose libclang is loadable by bindgen.
5+
6+
inputs:
7+
arch:
8+
description: CPU architecture (x64, Win32, arm64)
9+
required: true
10+
11+
runs:
12+
using: composite
13+
steps:
14+
- uses: dtolnay/rust-toolchain@1.91.1
15+
with:
16+
targets: i686-pc-windows-msvc,x86_64-pc-windows-msvc,aarch64-pc-windows-msvc
17+
- name: Install LLVM for bindgen
18+
if: inputs.arch != 'arm64'
19+
shell: cmd
20+
run: |
21+
choco install llvm --allow-downgrade --no-progress --version 21.1.0
22+
if not exist "C:\Program Files\LLVM\bin\libclang.dll" exit /b 1
23+
echo LIBCLANG_PATH=C:\Program Files\LLVM\bin>> "%GITHUB_ENV%"
24+
echo LLVMInstallDir=C:\Program Files\LLVM>> "%GITHUB_ENV%"
25+
# Chocolatey's LLVM package only ships x64 binaries, which an ARM64-native
26+
# cargo process cannot load. Install the official ARM64 build directly.
27+
- name: Install LLVM for bindgen (ARM64)
28+
if: inputs.arch == 'arm64'
29+
shell: pwsh
30+
run: |
31+
$installer = Join-Path $env:RUNNER_TEMP 'LLVM-21.1.0-woa64.exe'
32+
Invoke-WebRequest 'https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.0/LLVM-21.1.0-woa64.exe' -OutFile $installer
33+
Start-Process -Wait -FilePath $installer -ArgumentList '/S','/D=C:\Program Files\LLVM'
34+
if (!(Test-Path 'C:\Program Files\LLVM\bin\libclang.dll')) { exit 1 }
35+
echo "LIBCLANG_PATH=C:\Program Files\LLVM\bin" >> $env:GITHUB_ENV
36+
echo "LLVMInstallDir=C:\Program Files\LLVM" >> $env:GITHUB_ENV

.github/workflows/reusable-windows-msi.yml

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,9 @@ jobs:
2626
- uses: actions/checkout@v4
2727
with:
2828
persist-credentials: false
29-
- uses: dtolnay/rust-toolchain@1.91.1
29+
- uses: ./.github/setup-rust-windows
3030
with:
31-
targets: i686-pc-windows-msvc,x86_64-pc-windows-msvc,aarch64-pc-windows-msvc
32-
- name: Install LLVM for bindgen
33-
if: inputs.arch != 'arm64'
34-
shell: cmd
35-
run: |
36-
choco install llvm --allow-downgrade --no-progress --version 21.1.0
37-
if not exist "C:\Program Files\LLVM\bin\libclang.dll" exit /b 1
38-
echo LIBCLANG_PATH=C:\Program Files\LLVM\bin>> "%GITHUB_ENV%"
39-
echo LLVMInstallDir=C:\Program Files\LLVM>> "%GITHUB_ENV%"
40-
# Chocolatey's LLVM package only ships x64 binaries, which an ARM64-native
41-
# cargo process cannot load. Install the official ARM64 build directly.
42-
- name: Install LLVM for bindgen (ARM64)
43-
if: inputs.arch == 'arm64'
44-
shell: pwsh
45-
run: |
46-
$installer = Join-Path $env:RUNNER_TEMP 'LLVM-21.1.0-woa64.exe'
47-
Invoke-WebRequest 'https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.0/LLVM-21.1.0-woa64.exe' -OutFile $installer
48-
Start-Process -Wait -FilePath $installer -ArgumentList '/S','/D=C:\Program Files\LLVM'
49-
if (!(Test-Path 'C:\Program Files\LLVM\bin\libclang.dll')) { exit 1 }
50-
echo "LIBCLANG_PATH=C:\Program Files\LLVM\bin" >> $env:GITHUB_ENV
51-
echo "LLVMInstallDir=C:\Program Files\LLVM" >> $env:GITHUB_ENV
31+
arch: ${{ inputs.arch }}
5232
- name: Build CPython installer
5333
run: ./Tools/msi/build.bat --doc -"${ARCH}"
5434
shell: bash

.github/workflows/reusable-windows.yml

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,9 @@ jobs:
2929
- uses: actions/checkout@v4
3030
with:
3131
persist-credentials: false
32-
- uses: dtolnay/rust-toolchain@1.91.1
32+
- uses: ./.github/setup-rust-windows
3333
with:
34-
targets: i686-pc-windows-msvc,x86_64-pc-windows-msvc,aarch64-pc-windows-msvc
35-
- name: Install LLVM for bindgen
36-
if: inputs.arch != 'arm64'
37-
shell: cmd
38-
run: |
39-
choco install llvm --allow-downgrade --no-progress --version 21.1.0
40-
if not exist "C:\Program Files\LLVM\bin\libclang.dll" exit /b 1
41-
echo LIBCLANG_PATH=C:\Program Files\LLVM\bin>> "%GITHUB_ENV%"
42-
echo LLVMInstallDir=C:\Program Files\LLVM>> "%GITHUB_ENV%"
43-
# Chocolatey's LLVM package only ships x64 binaries, which an ARM64-native
44-
# cargo process cannot load. Install the official ARM64 build directly.
45-
- name: Install LLVM for bindgen (ARM64)
46-
if: inputs.arch == 'arm64'
47-
shell: pwsh
48-
run: |
49-
$installer = Join-Path $env:RUNNER_TEMP 'LLVM-21.1.0-woa64.exe'
50-
Invoke-WebRequest 'https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.0/LLVM-21.1.0-woa64.exe' -OutFile $installer
51-
Start-Process -Wait -FilePath $installer -ArgumentList '/S','/D=C:\Program Files\LLVM'
52-
if (!(Test-Path 'C:\Program Files\LLVM\bin\libclang.dll')) { exit 1 }
53-
echo "LIBCLANG_PATH=C:\Program Files\LLVM\bin" >> $env:GITHUB_ENV
54-
echo "LLVMInstallDir=C:\Program Files\LLVM" >> $env:GITHUB_ENV
34+
arch: ${{ inputs.arch }}
5535
- name: Register MSVC problem matcher
5636
if: inputs.arch != 'Win32'
5737
run: echo "::add-matcher::.github/problem-matchers/msvc.json"

Modules/cpython-sys/build.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ fn emit_rerun_instructions(builddir: Option<&str>) {
3030
for var in [
3131
"IPHONEOS_DEPLOYMENT_TARGET",
3232
"LLVM_TARGET",
33+
"PY_DEBUG",
34+
"PY_GIL_DISABLED",
3335
"PYTHON_BUILD_DIR",
3436
"PY_CC",
3537
"PY_CPPFLAGS",
@@ -68,10 +70,9 @@ fn gil_disabled(srcdir: &Path, builddir: Option<&str>) -> bool {
6870
}
6971

7072
fn env_var_is_truthy(name: &str) -> bool {
71-
matches!(
72-
env::var(name).as_deref(),
73-
Ok("1") | Ok("true") | Ok("TRUE") | Ok("yes") | Ok("YES")
74-
)
73+
env::var(name)
74+
.map(|v| matches!(v.to_ascii_lowercase().as_str(), "1" | "true" | "yes"))
75+
.unwrap_or(false)
7576
}
7677

7778
fn generate_c_api_bindings(

0 commit comments

Comments
 (0)