Skip to content

Commit

Permalink
use --config-settings when building on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nulano committed Jun 24, 2023
1 parent c068af7 commit 5d0e37e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 87 deletions.
16 changes: 6 additions & 10 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ install:
- path C:\pillow\winbuild\build\bin;%PATH%

build_script:
- ps: |
c:\pillow\winbuild\build\build_pillow.cmd install
$host.SetShouldExit(0)
- cd c:\pillow
- winbuild\build\build_env.cmd
- '%PYTHON%\%EXECUTABLE% -m pip install -v -C raqm=vendor -C fribidi=vendor .'
- '%PYTHON%\%EXECUTABLE% selftest.py --installed'

test_script:
Expand All @@ -63,18 +62,15 @@ cache:
- '%LOCALAPPDATA%\pip\Cache'

artifacts:
- path: pillow\dist\*.egg
- path: pillow\*.egg
name: egg
- path: pillow\dist\*.wheel
- path: pillow\*.whl
name: wheel

before_deploy:
- cd c:\pillow
- '%PYTHON%\%EXECUTABLE% -m pip install wheel'
- cd c:\pillow\winbuild\
- c:\pillow\winbuild\build\build_pillow.cmd --global-option="bdist_wheel"
- cd c:\pillow
- ps: Get-ChildItem .\dist\*.* | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
- '%PYTHON%\%EXECUTABLE% -m pip wheel -v -C raqm=vendor -C fribidi=vendor .'
- ps: Get-ChildItem .\*.whl | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }

deploy:
provider: S3
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
- name: Prepare build
if: steps.build-cache.outputs.cache-hit != 'true'
run: |
& python.exe winbuild\build_prepare.py -v --python $env:pythonLocation
& python.exe winbuild\build_prepare.py -v
shell: pwsh

- name: Build dependencies / libjpeg-turbo
Expand Down Expand Up @@ -165,9 +165,9 @@ jobs:

- name: Build Pillow
run: |
$FLAGS=""
if ('${{ github.event_name }}' -ne 'pull_request') { $FLAGS='--global-option="--disable-imagequant"' }
& winbuild\build\build_pillow.cmd $FLAGS --global-option="install"
$FLAGS="-C raqm=vendor -C fribidi=vendor"
if ('${{ github.event_name }}' -ne 'pull_request') { $FLAGS+=" -C imagequant=disable" }
cmd /c "winbuild\build\build_env.cmd && $env:pythonLocation\python.exe -m pip install -v $FLAGS ."
& $env:pythonLocation\python.exe selftest.py --installed
shell: pwsh

Expand Down Expand Up @@ -231,15 +231,16 @@ jobs:
)
)
for /f "tokens=3 delims=/" %%a in ("${{ github.ref }}") do echo dist=dist-%%a >> %GITHUB_OUTPUT%
winbuild\\build\\build_pillow.cmd --global-option="--disable-imagequant" --global-option="bdist_wheel"
call winbuild\\build\\build_env.cmd
%pythonLocation%\python.exe -m pip wheel -v -C raqm=vendor -C fribidi=vendor -C imagequant=disable .
shell: cmd

- name: Upload wheel
uses: actions/upload-artifact@v3
if: "github.event_name != 'pull_request'"
with:
name: ${{ steps.wheel.outputs.dist }}
path: dist\*.whl
path: "*.whl"

- name: Upload fribidi.dll
if: "github.event_name != 'pull_request' && matrix.python-version == 3.11"
Expand Down
102 changes: 31 additions & 71 deletions winbuild/build_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@ def cmd_msbuild(
"ARM64": {"vcvars_arch": "x86_arm64", "msbuild_arch": "ARM64"},
}

header = [
cmd_set("INCLUDE", "{inc_dir}"),
cmd_set("INCLIB", "{lib_dir}"),
cmd_set("LIB", "{lib_dir}"),
cmd_append("PATH", "{bin_dir}"),
]

# dependencies, listed in order of compilation
deps = {
"libjpeg": {
Expand Down Expand Up @@ -401,33 +394,26 @@ def find_msvs():
print("Visual Studio seems to be missing C compiler")
return None

vs = {
"header": [],
# nmake selected by vcvarsall
"nmake": "nmake.exe",
"vs_dir": vspath,
}

# vs2017
msbuild = os.path.join(vspath, "MSBuild", "15.0", "Bin", "MSBuild.exe")
if os.path.isfile(msbuild):
vs["msbuild"] = f'"{msbuild}"'
else:
if not os.path.isfile(msbuild):
# vs2019
msbuild = os.path.join(vspath, "MSBuild", "Current", "Bin", "MSBuild.exe")
if os.path.isfile(msbuild):
vs["msbuild"] = f'"{msbuild}"'
else:
if not os.path.isfile(msbuild):
print("Visual Studio MSBuild not found")
return None

vcvarsall = os.path.join(vspath, "VC", "Auxiliary", "Build", "vcvarsall.bat")
if not os.path.isfile(vcvarsall):
print("Visual Studio vcvarsall not found")
return None
vs["header"].append(f'call "{vcvarsall}" {{vcvars_arch}}')

return vs
return {
"vs_dir": vspath,
"msbuild": f'"{msbuild}"',
"vcvarsall": f'"{vcvarsall}"',
"nmake": "nmake.exe", # nmake selected by vcvarsall
}


def extract_dep(url, filename):
Expand Down Expand Up @@ -497,6 +483,22 @@ def get_footer(dep):
return lines


def build_env():
lines = [
"if defined DISTUTILS_USE_SDK goto end",
cmd_set("INCLUDE", "{inc_dir}"),
cmd_set("INCLIB", "{lib_dir}"),
cmd_set("LIB", "{lib_dir}"),
cmd_append("PATH", "{bin_dir}"),
f"call {{vcvarsall}} {{vcvars_arch}}",
cmd_set("DISTUTILS_USE_SDK", "1"), # use same compiler to build Pillow
cmd_set("py_vcruntime_redist", "true"), # always use /MD, never /MT
":end",
"@echo on",
]
write_script("build_env.cmd", lines)


def build_dep(name):
dep = deps[name]
dir = dep["dir"]
Expand Down Expand Up @@ -534,11 +536,11 @@ def build_dep(name):

banner = f"Building {name} ({dir})"
lines = [
rf'call "{{build_dir}}\build_env.cmd"',
"@echo " + ("=" * 70),
f"@echo ==== {banner:<60} ====",
"@echo " + ("=" * 70),
"cd /D %s" % os.path.join(sources_dir, dir),
*prefs["header"],
cmd_cd(os.path.join(sources_dir, dir)),
*dep.get("build", []),
*get_footer(dep),
]
Expand All @@ -548,7 +550,7 @@ def build_dep(name):


def build_dep_all():
lines = ["@echo on"]
lines = [r'call "{build_dir}\build_env.cmd"']
for dep_name in deps:
print()
if dep_name in disabled:
Expand All @@ -562,32 +564,16 @@ def build_dep_all():
write_script("build_dep_all.cmd", lines)


def build_pillow():
lines = [
"@echo ---- Building Pillow (build_ext %*) ----",
cmd_cd("{pillow_dir}"),
*prefs["header"],
cmd_set("DISTUTILS_USE_SDK", "1"), # use same compiler to build Pillow
cmd_set("py_vcruntime_redist", "true"), # always use /MD, never /MT
r'"{python_dir}\{python_exe}" -m pip install . '
r'--global-option="--vendor-raqm" '
r'--global-option="--vendor-fribidi" '
r"%*",
]

write_script("build_pillow.cmd", lines)


if __name__ == "__main__":
winbuild_dir = os.path.dirname(os.path.realpath(__file__))
pillow_dir = os.path.realpath(os.path.join(winbuild_dir, ".."))

parser = argparse.ArgumentParser(
prog="winbuild\\build_prepare.py",
description="Download dependencies and generate build scripts for Pillow.",
description="Download and generate build scripts for Pillow dependencies.",
epilog="""Arguments can also be supplied using the environment variables
PILLOW_BUILD, PILLOW_DEPS, ARCHITECTURE, PYTHON, EXECUTABLE.
See winbuild\\build.rst for more information.""",
PILLOW_BUILD, PILLOW_DEPS, ARCHITECTURE. See winbuild\\build.rst
for more information.""",
)
parser.add_argument(
"-v", "--verbose", action="store_true", help="print generated scripts"
Expand Down Expand Up @@ -622,20 +608,6 @@ def build_pillow():
),
help="build architecture (default: same as host Python)",
)
parser.add_argument(
"--python",
dest="python_dir",
metavar="PYTHON",
default=os.environ.get("PYTHON"),
help="Python install directory (default: use host Python)",
)
parser.add_argument(
"--executable",
dest="python_exe",
metavar="EXECUTABLE",
default=os.environ.get("EXECUTABLE", "python.exe"),
help="Python executable (default: use host Python)",
)
parser.add_argument(
"--nmake",
dest="cmake_generator",
Expand All @@ -660,11 +632,6 @@ def build_pillow():
arch_prefs = architectures[args.architecture]
print("Target architecture:", args.architecture)

if args.python_dir is None:
args.python_dir = os.path.dirname(os.path.realpath(sys.executable))
args.python_exe = os.path.basename(sys.executable)
print("Target Python:", os.path.join(args.python_dir, args.python_exe))

msvs = find_msvs()
if msvs is None:
msg = "Visual Studio not found. Please install Visual Studio 2017 or newer."
Expand Down Expand Up @@ -702,9 +669,6 @@ def build_pillow():
disabled += ["fribidi"]

prefs = {
# Python paths / preferences
"python_dir": args.python_dir,
"python_exe": args.python_exe,
"architecture": args.architecture,
**arch_prefs,
# Pillow paths
Expand All @@ -722,8 +686,6 @@ def build_pillow():
"cmake": "cmake.exe", # TODO find CMAKE automatically
"cmake_generator": args.cmake_generator,
# TODO find NASM automatically
# script header
"header": sum([header, msvs["header"], ["@echo on"]], []),
}

for k, v in deps.items():
Expand All @@ -732,7 +694,5 @@ def build_pillow():
print()

write_script(".gitignore", ["*"])
build_env()
build_dep_all()
if args.verbose:
print()
build_pillow()

0 comments on commit 5d0e37e

Please sign in to comment.