Skip to content

Commit

Permalink
Attempt to download MSVC from GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadoum committed Dec 27, 2023
1 parent 8ea4406 commit 7071f2c
Showing 1 changed file with 107 additions and 2 deletions.
109 changes: 107 additions & 2 deletions .github/workflows/build-qt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ jobs:
version: '5.15.2'
host: 'windows'
target: 'desktop'
dir: '${{github.workspace}}/qt/'
arch: 'win64_msvc2015_64'
archives: 'qtbase'

Expand All @@ -272,17 +273,121 @@ jobs:
// default directories to be searched for libraries when linking
lib-dirs = [
"$HOME/ldc2-1.33.0-windows-x64/lib",
"${{github.workspace}}/msvc/VC/Tools/MSVC/14.38.33130/lib/x64",
"$Qt5_DIR/lib",
];
};
EOF
curl -LO https://github.com/ldc-developers/ldc/releases/download/v1.33.0/ldc2-1.33.0-windows-x64.7z
7z x ./ldc2-1.33.0-windows-x64.7z -o$HOME
- name: Set-up Qt for cross-compilation
- name: Set-up LDC2 for cross-compilation
run: |
cp -r $Qt5_DIR/lib/* $HOME/ldc2-1.33.0-windows-x64/lib
ln $HOME/ldc2-1.33.0-windows-x64/lib/mingw/msvcrt.lib $HOME/ldc2-1.33.0-windows-x64/lib/mingw/MSVCRT.lib
ln $HOME/ldc2-1.33.0-windows-x64/lib/mingw/oldnames.lib $HOME/ldc2-1.33.0-windows-x64/lib/mingw/OLDNAMES.lib
python3 << EOF
# SOURCE: https://gist.github.com/mmozeiko/7f3162ec2988e81e56d5c4e22cde9977
# Edits to make it non-interactive and smaller.
import io
import os
import sys
import json
import shutil
import hashlib
import zipfile
import tempfile
import argparse
import subprocess
import urllib.request
from pathlib import Path
OUTPUT = Path("${{github.workspace}}/msvc") # output folder
# other architectures may work or may not - not really tested
HOST = "x64" # or x86
TARGET = "x64" # or x86, arm, arm64
MANIFEST_URL = "https://aka.ms/vs/17/release/channel"
def download(url):
with urllib.request.urlopen(url) as res:
return res.read()
def download_progress(url, check, name, f):
data = io.BytesIO()
with urllib.request.urlopen(url) as res:
total = int(res.headers["Content-Length"])
size = 0
while True:
block = res.read(1 << 20)
if not block:
break
f.write(block)
data.write(block)
size += len(block)
perc = size * 100 // total
print(f"\r{name} ... {perc}%", end="")
print()
data = data.getvalue()
digest = hashlib.sha256(data).hexdigest()
if check.lower() != digest:
exit(f"Hash mismatch for f{pkg}")
return data
def first(items, cond):
return next(item for item in items if cond(item))
### get main manifest
manifest = json.loads(download(MANIFEST_URL))
### download VS manifest
vs = first(manifest["channelItems"], lambda x: x["id"] == "Microsoft.VisualStudio.Manifests.VisualStudio")
payload = vs["payloads"][0]["url"]
vsmanifest = json.loads(download(payload))
### find MSVC & WinSDK versions
packages = {}
for p in vsmanifest["packages"]:
packages.setdefault(p["id"].lower(), []).append(p)
msvc = {}
sdk = {}
for pid, p in packages.items():
if pid.startswith("Microsoft.VisualStudio.Component.VC.".lower()) and pid.endswith(".x86.x64".lower()):
pver = ".".join(pid.split(".")[4:6])
if pver[0].isnumeric():
msvc[pver] = pid
msvc_ver = "14.38.33130"
msvc_pid = msvc[msvc_ver]
msvc_ver = ".".join(msvc_pid.split(".")[4:-2])
OUTPUT.mkdir(exist_ok=True)
total_download = 0
pkg = f"microsoft.vc.{msvc_ver}.crt.{TARGET}.store.base"
p = first(packages[pkg], lambda p: p.get("language") in (None, "en-US"))
for payload in p["payloads"]:
with tempfile.TemporaryFile() as f:
data = download_progress(payload["url"], payload["sha256"], pkg, f)
total_download += len(data)
with zipfile.ZipFile(f) as z:
for name in z.namelist():
if name.startswith("Contents/"):
out = OUTPUT / Path(name).relative_to("Contents")
out.parent.mkdir(parents=True, exist_ok=True)
out.write_bytes(z.read(name))
EOF
- name: Write version file
run: echo 'module version_string; enum versionStr = "Sideloader automated build, branch ${{ github.ref_name }}, commit ${{ github.sha }}";' > source/version_string.d
Expand Down

0 comments on commit 7071f2c

Please sign in to comment.