Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci] Switch Windows build script to build.py #6993

Merged
merged 52 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
af13a26
Temp remove testing(save time)
feisuzhu Dec 28, 2022
df4ef21
switch windows build script
feisuzhu Dec 28, 2022
5c268e5
should fail
feisuzhu Dec 28, 2022
34be3d0
setup clang
feisuzhu Dec 28, 2022
7148035
check local cache size
feisuzhu Dec 28, 2022
47804c9
tinysh use subprocess
feisuzhu Dec 28, 2022
d32838b
win miniforge fix
feisuzhu Dec 28, 2022
e78abfd
meh
feisuzhu Dec 28, 2022
d36fe31
meh
feisuzhu Dec 28, 2022
567623f
meh
feisuzhu Dec 28, 2022
711f924
conda
feisuzhu Dec 29, 2022
a52ff8d
path quirk
feisuzhu Dec 29, 2022
d09d972
win llvm strip
feisuzhu Dec 29, 2022
642f678
Revert "Temp remove testing(save time)"
feisuzhu Jan 4, 2023
7156f6d
Merge remote-tracking branch 'upstream/master' into feat/windows-build
feisuzhu Jan 4, 2023
a80dc3a
Disable tests (2nd)
feisuzhu Jan 4, 2023
1b0c151
vulkan
feisuzhu Jan 5, 2023
58ddbd3
minoor
feisuzhu Jan 6, 2023
a0a6cbd
Merge remote-tracking branch 'upstream/master' into feat/windows-build
feisuzhu Jan 6, 2023
eee4a1e
revert to plain os.environ
feisuzhu Jan 9, 2023
3f7a798
meh
feisuzhu Jan 9, 2023
54b3bce
meh
feisuzhu Jan 9, 2023
9deac6f
meh
feisuzhu Jan 9, 2023
e530911
setup msvc
feisuzhu Jan 10, 2023
f2ab6ff
Merge remote-tracking branch 'upstream/master' into feat/windows-build
feisuzhu Jan 10, 2023
e635298
auto install vc buildtools 2022
feisuzhu Jan 10, 2023
c046968
Revert "Disable tests (2nd)"
feisuzhu Jan 16, 2023
fef6e6b
Merge remote-tracking branch 'upstream/master' into feat/windows-build
feisuzhu Jan 16, 2023
951629b
meh
feisuzhu Jan 16, 2023
d9ff019
REMOVE OTHER STEPS FOR DEBUG
feisuzhu Jan 16, 2023
42b310e
use cmd
feisuzhu Jan 16, 2023
509ce05
fixup
feisuzhu Jan 16, 2023
191f28d
meh
feisuzhu Jan 16, 2023
b727a10
meh
feisuzhu Jan 16, 2023
b02ac5a
meh
feisuzhu Jan 16, 2023
3cd21bb
isolated dependency dir for build.py
feisuzhu Jan 16, 2023
120b751
clean build env
feisuzhu Jan 16, 2023
8c5fcc9
cmake env
feisuzhu Jan 16, 2023
1f555c3
more isolated
feisuzhu Jan 16, 2023
80b4b39
meh
feisuzhu Jan 16, 2023
53d95db
meh
feisuzhu Jan 17, 2023
6f11675
meh
feisuzhu Jan 17, 2023
04915b8
clang
feisuzhu Jan 17, 2023
1a62b1b
fix
feisuzhu Jan 17, 2023
a6861e4
Revert "REMOVE OTHER STEPS FOR DEBUG"
feisuzhu Jan 17, 2023
9ef900e
Merge remote-tracking branch 'upstream/master' into feat/windows-build
feisuzhu Jan 17, 2023
27956a5
remove todo
feisuzhu Jan 17, 2023
bf80b99
vs2022 packages
feisuzhu Jan 17, 2023
7f41f3f
move vulkan on to testing.yml
feisuzhu Jan 17, 2023
6896856
clean up debug messes
feisuzhu Jan 17, 2023
7e30bd2
resolve clang++ path pollution
feisuzhu Jan 17, 2023
966b26d
path escaping
feisuzhu Jan 17, 2023
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
39 changes: 35 additions & 4 deletions .github/workflows/scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
# -- third party --
# -- own --
from ci_common.dep import download_dep
from ci_common.misc import banner, get_cache_home, is_manylinux2014
from ci_common.misc import (banner, concat_paths, get_cache_home,
is_manylinux2014)
from ci_common.python import setup_python
from ci_common.sccache import setup_sccache
from ci_common.tinysh import Command, environ, git, sh


# -- code --
@banner('Setup LLVM')
def setup_llvm(env_out: dict) -> None:
@banner('Setup Clang')
def setup_clang(env_out: dict) -> None:
'''
Download and install LLVM.
Setup Clang.
'''
u = platform.uname()
if u.system == 'Linux':
Expand All @@ -32,6 +33,30 @@ def setup_llvm(env_out: dict) -> None:
lnsf('/usr/bin/clang++-10', '/usr/bin/clang++')
lnsf('/usr/bin/clang-10', '/usr/bin/clang')
lnsf('/usr/bin/ld.lld-10', '/usr/bin/ld.lld')
elif (u.system, u.machine) == ('Windows', 'AMD64'):
out = get_cache_home() / 'clang-15'
url = 'https://github.com/python3kgae/taichi_assets/releases/download/llvm15_vs2022_clang/clang-15.0.0-win.zip'
feisuzhu marked this conversation as resolved.
Show resolved Hide resolved
download_dep(url, out)
env_out['PATH'] = concat_paths(out / 'bin', env_out.get('PATH'))
env_out[
'TAICHI_CMAKE_ARGS'] += ' -DCLANG_EXECUTABLE=clang++.exe' # TODO: Can this be omitted?
env_out[
'TAICHI_CMAKE_ARGS'] += ' -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang'
bobcao3 marked this conversation as resolved.
Show resolved Hide resolved
else:
# TODO: unify all
pass


@banner('Setup LLVM')
def setup_llvm(env_out: dict) -> None:
'''
Download and install LLVM.
'''
u = platform.uname()
if u.system == 'Linux':
if 'AMDGPU_TEST' in os.environ:
# FIXME: AMDGPU bots are currently maintained separately,
# we should unify them with the rest of the bots.
env_out['LLVM_DIR'] = '/taichi-llvm-15'
return
elif is_manylinux2014():
Expand All @@ -47,10 +72,15 @@ def setup_llvm(env_out: dict) -> None:
elif (u.system, u.machine) == ('Darwin', 'x86_64'):
out = get_cache_home() / 'llvm15-mac'
url = 'https://github.com/taichi-dev/taichi_assets/releases/download/llvm15/llvm-15-mac10.15.zip'
elif (u.system, u.machine) == ('Windows', 'AMD64'):
out = get_cache_home() / 'llvm15-win'
url = 'https://github.com/python3kgae/taichi_assets/releases/download/llvm15_vs2019_clang/taichi-llvm-15.0.0-msvc2019.zip'
feisuzhu marked this conversation as resolved.
Show resolved Hide resolved
env_out['TAICHI_CMAKE_ARGS'] += " -DLLVM_AS_EXECUTABLE=llvm-as.exe"
bobcao3 marked this conversation as resolved.
Show resolved Hide resolved
else:
raise RuntimeError(f'Unsupported platform: {u.system} {u.machine}')

download_dep(url, out, strip=1)
env_out['PATH'] = concat_paths(out / 'bin', env_out.get('PATH'))
env_out['LLVM_DIR'] = str(out)


Expand Down Expand Up @@ -110,6 +140,7 @@ def main() -> None:
'TAICHI_CMAKE_ARGS': os.environ.get('TAICHI_CMAKE_ARGS', ''),
'PROJECT_NAME': os.environ.get('PROJECT_NAME', 'taichi'),
}
setup_clang(env)
setup_llvm(env)
setup_vulkan(env)
sccache = setup_sccache(env)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scripts/ci_common/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def chdir_to_root():
root = Path('/')
p = Path(__file__).resolve()
while p != root:
if (p / '.git').exists():
if (p / 'setup.py').exists():
os.chdir(p)
break
p = p.parent
Expand Down
40 changes: 23 additions & 17 deletions .github/workflows/scripts/ci_common/dep.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# -- own --
from .misc import get_cache_home
from .tinysh import bash, sh, tar
from .tinysh import bash, sh, start, tar


# -- code --
Expand Down Expand Up @@ -55,7 +55,7 @@ def escape_url(url):
return url.replace('/', '_').replace(':', '_')


def download_dep(url, outdir, *, strip=0, force=False, args=[]):
def download_dep(url, outdir, *, strip=0, force=False, args=None):
'''
Download a dependency archive from `url` and expand it to `outdir`,
optionally stripping `strip` components.
Expand All @@ -73,22 +73,24 @@ def download_dep(url, outdir, *, strip=0, force=False, args=[]):
depcache.mkdir(parents=True, exist_ok=True)
local_cached = depcache / escaped

near_caches = [
f'http://botmaster.tgr:9000/misc/depcache/{escaped}/{name}'
f'https://taichi-bots.oss-cn-beijing.aliyuncs.com/depcache/{escaped}/{name}'
urls = [
f'http://botmaster.tgr:9000/misc/depcache/{escaped}/{name}',
f'https://taichi-bots.oss-cn-beijing.aliyuncs.com/depcache/{escaped}/{name}',
url,
]

if not local_cached.exists():
for u in near_caches:
try:
resp = requests.head(u, timeout=1)
if resp.ok:
print('Using near cache: ', u)
url = u
break
except Exception:
pass

size = -1
for u in urls:
try:
resp = requests.head(u, timeout=1)
if resp.ok:
url = u
size = int(resp.headers['Content-Length'])
break
except Exception:
pass

if not local_cached.exists() or local_cached.stat().st_size != size:
import tqdm

with requests.get(url, stream=True) as r:
Expand All @@ -112,8 +114,12 @@ def download_dep(url, outdir, *, strip=0, force=False, args=[]):
tar('-xzf', local_cached, '-C', outdir, f'--strip-components={strip}')
elif name.endswith('.sh'):
bash(local_cached, *args)
elif name.endswith('.exe') or '.' not in name:
elif '.' not in name and args is not None:
local_cached.chmod(0o755)
sh.bake(local_cached)(*args)
elif name.endswith('.exe') and args is not None:
local_cached.chmod(0o755)
sh.bake(local_cached)(*args)
# start(local_cached, *args)
else:
raise RuntimeError(f'Unknown file type: {name}')
9 changes: 8 additions & 1 deletion .github/workflows/scripts/ci_common/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import platform
import sys
from pathlib import Path
from typing import Callable
from typing import Any, Callable

# -- third party --
# -- own --
Expand Down Expand Up @@ -65,3 +65,10 @@ def wrapper(*args, **kwargs):
return wrapper

return decorate


def concat_paths(*paths: Any) -> str:
'''
Concatenate paths together.
'''
return os.pathsep.join(str(p) for p in paths if p)
40 changes: 33 additions & 7 deletions .github/workflows/scripts/ci_common/python.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
# -*- coding: utf-8 -*-

import os
import platform
import shutil
from typing import Optional, Tuple

from .dep import download_dep
from .misc import banner, get_cache_home
from .misc import banner, concat_paths, get_cache_home
from .tinysh import Command, sh


def setup_miniforge3(prefix):
u = platform.uname()
if u.system == "Linux":
url = 'https://github.com/conda-forge/miniforge/releases/download/22.9.0-2/Miniforge3-22.9.0-2-Linux-x86_64.sh'
download_dep(url, prefix, args=['-bfp', str(prefix)])
elif (u.system, u.machine) == ("Darwin", "arm64"):
url = 'https://github.com/conda-forge/miniforge/releases/download/22.9.0-2/Miniforge3-22.9.0-2-MacOSX-arm64.sh'
download_dep(url, prefix, args=['-bfp', str(prefix)])
elif (u.system, u.machine) == ("Darwin", "x86_64"):
url = 'https://github.com/conda-forge/miniforge/releases/download/22.9.0-2/Miniforge3-22.9.0-2-MacOSX-x86_64.sh'
download_dep(url, prefix, args=['-bfp', str(prefix)])
elif u.system == "Windows":
url = 'https://github.com/conda-forge/miniforge/releases/download/22.9.0-2/Miniforge3-22.9.0-2-Windows-x86_64.exe'
download_dep(url,
prefix,
args=[
'/S',
'/InstallationType=JustMe',
'/RegisterPython=0',
'/KeepPkgCache=0',
'/AddToPath=0',
'/NoRegistry=1',
'/NoShortcut=1',
'/NoScripts=1',
'/CheckPathLength=1',
f'/D={prefix}',
])
else:
raise RuntimeError(f"Unsupported platform: {u.system} {u.machine}")

download_dep(url, prefix, args=['-bfp', str(prefix)])


@banner('Setup Python {version}')
def setup_python(env_out: dict,
Expand All @@ -34,9 +48,16 @@ def setup_python(env_out: dict,
'''
assert version

windows = platform.system() == "Windows"

prefix = get_cache_home() / 'miniforge3'
setup_miniforge3(prefix)
conda_path = prefix / 'bin' / 'conda'

if windows:
conda_path = prefix / 'Scripts' / 'conda.exe'
else:
conda_path = prefix / 'bin' / 'conda'

if not conda_path.exists():
shutil.rmtree(prefix, ignore_errors=True)
setup_miniforge3(prefix)
Expand All @@ -46,12 +67,17 @@ def setup_python(env_out: dict,
conda = sh.bake(str(conda_path))

env = prefix / 'envs' / version
exe = env / 'bin' / 'python'
if windows:
exe = env / 'python.exe'
env_out['PATH'] = concat_paths(env, env / 'Scripts',
env_out.get('PATH'))
else:
exe = env / 'bin' / 'python'
env_out['PATH'] = concat_paths(env / 'bin', env_out.get('PATH'))

if not exe.exists():
conda.create('-y', '-n', version, f'python={version}')

env_out['PATH'] = f'{env / "bin"}:{env_out["PATH"]}'
python = sh.bake(str(exe))
pip = python.bake('-m', 'pip')

Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/scripts/ci_common/tinysh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import os
import platform
import shutil
import subprocess
import sys
from contextlib import contextmanager
from typing import Any, Mapping, Sequence
Expand Down Expand Up @@ -78,7 +80,9 @@ def __call__(self, *moreargs: Sequence[str]) -> None:
env = os.environ.copy()
env.update(overlay)

code = os.spawnvpe(os.P_WAIT, args[0], args, env)
exe = shutil.which(args[0])
proc = subprocess.Popen(args, executable=exe, env=env)
code = proc.wait()
if code:
cmd = ' '.join([quote(v) for v in args])
raise CommandFailed(cmd, code)
Expand Down Expand Up @@ -146,3 +150,4 @@ def sudo():
sccache = sh.sccache
tar = sh.tar
bash = sh.bash
start = sh.start.bake('/wait')
30 changes: 8 additions & 22 deletions .github/workflows/scripts/win_build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ param (
[switch]$installVulkan = $false,
[switch]$develop = $false,
[switch]$install = $false,
[string]$libsDir = ".",
[string]$llvmVer = "10"
[string]$libsDir = "."
)

$ErrorActionPreference = "Stop"
Expand Down Expand Up @@ -49,26 +48,13 @@ function DownloadDep {
}
}

if ($llvmVer -eq "10") {
DownloadDep LLVM llvm.zip taichi_llvm `
https://github.com/taichi-dev/taichi_assets/releases/download/llvm10/taichi-llvm-10.0.0-msvc2019.zip
DownloadDep Clang clang.zip taichi_clang `
https://github.com/taichi-dev/taichi_assets/releases/download/llvm10/clang-10.0.0-win.zip
$env:LLVM_DIR = "$libsDir\taichi_llvm"
$env:TAICHI_CMAKE_ARGS += " -DCLANG_EXECUTABLE=$($libsDir -replace "\\", "\\")\\taichi_clang\\bin\\clang++.exe"
$env:TAICHI_CMAKE_ARGS += " -DLLVM_AS_EXECUTABLE=$($libsDir -replace "\\", "\\")\\taichi_llvm\\bin\\llvm-as.exe"
} elseif ($llvmVer -eq "15") {
DownloadDep LLVM-15 llvm-15.zip taichi_llvm_15 `
https://github.com/python3kgae/taichi_assets/releases/download/llvm15_vs2019_clang/taichi-llvm-15.0.0-msvc2019.zip
DownloadDep Clang-15 clang-15.zip taichi_clang_15 `
https://github.com/python3kgae/taichi_assets/releases/download/llvm15_vs2022_clang/clang-15.0.0-win.zip
$env:LLVM_DIR = "$libsDir\taichi_llvm_15"
$env:TAICHI_CMAKE_ARGS += " -DCLANG_EXECUTABLE=$($libsDir -replace "\\", "\\")\\taichi_clang_15\\bin\\clang++.exe"
$env:TAICHI_CMAKE_ARGS += " -DLLVM_AS_EXECUTABLE=$($libsDir -replace "\\", "\\")\\taichi_llvm_15\\bin\\llvm-as.exe"
} else {
throw "Unsupported LLVM version"
}

DownloadDep LLVM-15 llvm-15.zip taichi_llvm_15 `
https://github.com/python3kgae/taichi_assets/releases/download/llvm15_vs2019_clang/taichi-llvm-15.0.0-msvc2019.zip
DownloadDep Clang-15 clang-15.zip taichi_clang_15 `
https://github.com/python3kgae/taichi_assets/releases/download/llvm15_vs2022_clang/clang-15.0.0-win.zip
$env:LLVM_DIR = "$libsDir\taichi_llvm_15"
$env:TAICHI_CMAKE_ARGS += " -DCLANG_EXECUTABLE=$($libsDir -replace "\\", "\\")\\taichi_clang_15\\bin\\clang++.exe"
$env:TAICHI_CMAKE_ARGS += " -DLLVM_AS_EXECUTABLE=$($libsDir -replace "\\", "\\")\\taichi_llvm_15\\bin\\llvm-as.exe"
$env:TAICHI_CMAKE_ARGS += " -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang"

if ($installVulkan) {
Expand Down
Loading