Skip to content

Commit

Permalink
[ci] Polishing build.py, wave 2 (#7800)
Browse files Browse the repository at this point in the history
Issue: #7269 

### Brief Summary

- Setting a skbuild platform name to ensure the Android build can
coexist with the Linux build of the C-API shared library.
- Run ensurepip in bootstraping
- Probe mirror before use
  • Loading branch information
feisuzhu authored Apr 13, 2023
1 parent 5d2a462 commit a93690a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/scripts/aot-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ function prepare-unity-build-env {

export TAICHI_REPO_DIR=$(pwd)

setup-android-ndk-env
git clone --reference-if-able /var/lib/git-cache -b "$TAICHI_UNITY2_BRANCH" "$TAICHI_UNITY2_URL"
mkdir tu2-build
pushd tu2-build
cmake ../taichi-unity2 -DTAICHI_C_API_INSTALL_DIR=$TAICHI_REPO_DIR/_skbuild/linux-x86_64-3.9/cmake-install/c_api $TAICHI_CMAKE_ARGS
cmake ../taichi-unity2 $TAICHI_CMAKE_ARGS
cmake --build .
popd
cp tu2-build/bin/libtaichi_unity.so Taichi-UnityExample/Assets/Plugins/Android
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/scripts/ti_build/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def build_android(python: Command, pip: Command) -> None:
cmake_args['TI_WITH_C_API'] = True
cmake_args['TI_BUILD_TESTS'] = False
cmake_args.writeback()
os.environ['TAICHI_FORCE_PLAT_NAME'] = 'android-arm64' # affects setup.py
pip.install('-r', 'requirements_dev.txt')
python('setup.py', 'clean')
python('setup.py', 'build_ext')
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/scripts/ti_build/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ def ensure_dependencies(*deps: str):
sys.executable, '-m', 'pip', 'install', '--no-user',
f'--target={bootstrap_root}', '-U'
]
if run([sys.executable, '-m', 'ensurepip']):
raise Exception('Unable to run ensurepip!')
if run(*pipcmd, 'pip', 'setuptools'):
raise Exception('Unable to upgrade pip!')
raise Exception('Unable to install pip!')
if run(*pipcmd, *deps, env={'PYTHONPATH': str(bootstrap_root)}):
raise Exception('Unable to install dependencies!')

Expand Down
55 changes: 48 additions & 7 deletions .github/workflows/scripts/ti_build/dep.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import requests

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


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


SHOULD_USE_MIRROR = {
'ci': False,
'aliyun': False,
'_probed': False,
}


def probe_mirrors():
if SHOULD_USE_MIRROR['_probed']:
return

try:
resp = requests.get('http://botmaster.tgr:9000/misc/canary.txt',
timeout=0.5)
if resp.ok and resp.text.strip() == 'in-taichi-ci-environment':
info('Enabling Taichi CI cluster mirror')
SHOULD_USE_MIRROR['ci'] = True
except Exception:
pass

google_ok = True
try:
resp = requests.head('https://google.com', timeout=2)
google_ok = resp.ok
except Exception:
google_ok = False

if not google_ok:
info('Enabling Aliyun mirror')
SHOULD_USE_MIRROR['aliyun'] = True

SHOULD_USE_MIRROR['_probed'] = True


def download_dep(url,
outdir,
*,
Expand All @@ -80,14 +114,21 @@ def download_dep(url,
depcache.mkdir(parents=True, exist_ok=True)
local_cached = depcache / escaped

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

urls = [url]

if SHOULD_USE_MIRROR['aliyun']:
urls.append(
f'https://taichi-bots.oss-cn-beijing.aliyuncs.com/depcache/{escaped}/{name}'
)

if SHOULD_USE_MIRROR['ci']:
urls.append(
f'http://botmaster.tgr:9000/misc/depcache/{escaped}/{name}')

size = -1
for u in urls:
for u in reversed(urls):
try:
resp = requests.head(u,
headers={'Accept-Encoding': 'identity'},
Expand Down
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ def sign_development_for_apple_m1():


copy_assets()

force_plat_name = os.getenv('TAICHI_FORCE_PLAT_NAME', '').strip()
if force_plat_name:
from skbuild.constants import set_skbuild_plat_name
set_skbuild_plat_name(force_plat_name)

setup(name=project_name,
packages=packages,
package_dir={"": package_dir},
Expand Down

0 comments on commit a93690a

Please sign in to comment.