Skip to content

Commit bd7eb07

Browse files
Attempting to install flang based off of LLVM action
1 parent d898f94 commit bd7eb07

File tree

1 file changed

+87
-27
lines changed

1 file changed

+87
-27
lines changed

.github/workflows/build_wheels.yml

Lines changed: 87 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ jobs:
2626
python_version: "cp313-*"
2727

2828
steps:
29-
- name: Checkout repository
29+
- name: Checkout repository (for non-windows)
30+
if: matrix.os != 'windows-latest'
3031
uses: actions/checkout@v4
3132
with:
3233
submodules: true
@@ -123,47 +124,105 @@ jobs:
123124
with:
124125
python-version: '3.13'
125126

126-
- name: Install Windows Dependencies (Part 0a - Setup Build Env)
127-
uses: ilammy/msvc-dev-cmd@v1
127+
- name: Clean Windows Workspace
128+
if: ${{ matrix.os == 'windows-latest'}}
129+
run: Remove-Item * -Recurse -Force
128130

129-
- name: Install Windows Dependencies (Part 0b - Fetch LLVM Build Dependencies)
130-
if: matrix.os == 'windows-latest' # works on any OS, but we only need windows here(?)
131+
- name: Install Windows Dependencies (Part 0a - Setup Flang Source Code)
132+
if: ${{ matrix.os == 'windows-latest'}}
131133
run: |
132-
choco install ninja wget 7zip llvm -y
134+
git clone --depth 1 https://github.com/flang-compiler/flang.git ${{ github.workspace }}
133135
134-
- name: Install Windows Dependencies (Part 1 - Build Flang)
135-
if: matrix.os == 'windows-latest' # works on any OS, but we only need windows here(?)
136+
- name: Install Windows Dependencies (Part 0b - Setup LLVM Build Env)
137+
if: ${{ matrix.os == 'windows-latest'}}
138+
uses: llvm/actions/setup-windows@main
139+
with:
140+
arch: amd64
141+
142+
- name: Install Windows Dependencies (Part 0c - Setup LLVM-style Ninja Build Env)
143+
if: ${{ matrix.os == 'windows-latest'}}
144+
uses: llvm/actions/setup-windows@main
145+
with:
146+
arch: amd64
147+
148+
- name: Install Windows Dependencies (Part 0d - Setup Graphviz for Doxygen)
149+
if: ${{ matrix.os == 'windows-latest'}}
150+
run: choco install graphviz wget
151+
152+
- name: Install Windows Dependencies (Part 0e - Setup Sphinx for Python)
153+
if: ${{ matrix.os == 'windows-latest'}}
154+
run: pip install sphinx
155+
156+
- name: Install Windows Dependencies (Part 0f - Prepare Flang source)
157+
if : ${{ matrix.os == 'windows-latest'}}
158+
run: |
159+
git clone --depth 1 https://github.com/flang-compiler/flang.git /flang_build
160+
161+
- name: Install Windows Dependencies (Part 0g - Download pre-built "cmade" LLVM)
162+
run: |
163+
cd ../..
164+
# Search backwards in the workflow history for the specified branch
165+
# for the first successful run that produced the desired artifact.
166+
$build_name="llvm_build_win_amd64_clangcl_release_19x"
167+
Invoke-WebRequest -Uri https://api.github.com/repos/flang-compiler/classic-flang-llvm-project/actions/workflows/pre-compile_llvm.yml/runs -OutFile llvm_runs.json
168+
$urls = @($(jq -r --arg b release_19x '.workflow_runs[] | select(.head_branch == $b) | select (.conclusion == "success") | .artifacts_url?' llvm_runs.json))
169+
Invoke-WebRequest "$(jq -r '.workflow_runs[0].artifacts_url?' llvm_runs.json)" -OutFile llvm_artifacts.json
170+
for ($i = 0; $i -lt $urls.Count; $i++) {
171+
$artifacts_url = $urls[$i]
172+
Invoke-WebRequest -Uri "$artifacts_url" -OutFile llvm_artifacts.json
173+
$archive_url = "$(jq -r --arg b $build_name '.artifacts[] | select(.name == $b) | .archive_download_url' llvm_artifacts.json)"
174+
if (! $archive_url) {
175+
Write-Output "$artifacts_url did not contain a $build_name archive; too old?"
176+
continue
177+
}
178+
Write-Output "Downloading $archive_url."
179+
$artifact_path = "$pwd\${build_name}.zip"
180+
try {
181+
$response = Invoke-WebRequest -Method Get -Uri $archive_url -OutFile $artifact_path -Headers @{ "Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}" }
182+
if ($response.StatusCode -lt 300) {
183+
break
184+
}
185+
} catch {}
186+
}
187+
if (!(Test-Path "$artifact_path")) {
188+
Write-Output "Could not download the correct prebuilt compiler; aborting."
189+
exit 1
190+
}
191+
Expand-Archive -Force -Path "${build_name}.zip" -DestinationPath .
192+
& 7z x "$pwd\llvm_build.7z" -o"$pwd\classic-flang-llvm-project\" -y
193+
Write-Output "$(Get-ChildItem)"
194+
195+
196+
- name: Install Windows Dependencies (Part 1a - Build Flang)
197+
if: matrix.os == 'windows-latest'
198+
shell: powershell
199+
run: |
200+
$pcount = $($(Get-WmiObject -class Win32_ComputerSystem).numberoflogicalprocessors)
201+
python .\scripts\build_flang.py -i -d build -t X86 -p "$(pwd)\..\..\classic-flang-llvm-project\classic-flang-llvm-project\build\" -j $pcount -v
202+
203+
- name: Install Windows Dependencies (Part 1b - Confirm Neccessary LLVM Tools are Installed)
204+
if: matrix.os == 'windows-latest'
136205
run: |
137-
mkdir -p /flang_build/build
138-
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-20.1.2/flang-20.1.2.src.tar.xz
139-
echo 'Unpacking with 7-zip...' # for some reason, `tar` doesn't load properly...
140-
7z x "flang-20.1.2.src.tar.xz" -so | 7z x -aoa -si -ttar -o"d:\\flang_build"
141-
mv /flang_build/*.src/* /flang_build
142-
rm -r /flang_build/*.src
143-
echo "running cmake"
144-
cmake /flang_build -B /flang_build/build
145-
cmake --build /flang_build/build --config Release -j
146-
cmake --install /flang_build/build
147-
148206
clang --version
149207
clang++ --version
150208
flang --version
209+
which flang
210+
211+
- name: Install Windows Dependencies (Part 2a - Reclean Windows Workspace)
212+
if: ${{ matrix.os == 'windows-latest'}}
213+
run: Remove-Item * -Recurse -Force
151214

152-
# - name: Install Windows Dependencies (Part X - Clang set-up)
153-
# uses: KyleMayes/install-llvm-action@v2
154-
# if: matrix.os == 'windows-latest' # works on any OS, but we only need windows here(?)
155-
# with:
156-
# version: "19"
157-
# env: true # Sets CC and CXX to clang variants
215+
- name: Install Windows Dependencies (Part 2b - Setup Flang Source Code)
216+
if: ${{ matrix.os == 'windows-latest'}}
217+
uses: actions/checkout@v4
158218

159-
- name: Install Windows Dependencies (Part 2 - Remainder)
219+
- name: Install Windows Dependencies (Part 2c - Remainder)
160220
if: matrix.os == 'windows-latest'
161221
run: |
162222
choco install conan -y
163223
conan profile detect --force
164224
conan install . --output-folder=build --build=missing
165225
166-
167226
- name: Build Wheels (Windows)
168227
uses: pypa/[email protected]
169228
if: matrix.os == 'windows-latest'
@@ -175,6 +234,7 @@ jobs:
175234
CIBW_ENVIRONMENT: >
176235
CC=clang
177236
CXX=clang++
237+
FC=flang
178238
CMAKE_GENERATOR=Ninja
179239
# with:
180240
# package-dir: .

0 commit comments

Comments
 (0)