Skip to content

Commit 37f031d

Browse files
committed
switch to script
1 parent cab8076 commit 37f031d

File tree

2 files changed

+50
-116
lines changed

2 files changed

+50
-116
lines changed

.ci/scripts/wheel/pre_build_script.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,34 @@ fi
4444
# able to see the installed torch package.
4545

4646
"${GITHUB_WORKSPACE}/${REPOSITORY}/install_requirements.sh" --example
47+
48+
#!/usr/bin/env bash
49+
set -euxo pipefail
50+
51+
GLIBC_VERSION=2.29
52+
PREFIX=/tmp/glibc-$GLIBC_VERSION
53+
BUILD_DIR=/tmp/glibc-build
54+
55+
# Clean old dirs if they exist
56+
rm -rf "$PREFIX" "$BUILD_DIR"
57+
mkdir -p "$BUILD_DIR"
58+
59+
# Download
60+
curl -sSL https://ftp.gnu.org/gnu/libc/glibc-$GLIBC_VERSION.tar.xz -o /tmp/glibc-$GLIBC_VERSION.tar.xz
61+
tar -C /tmp -xf /tmp/glibc-$GLIBC_VERSION.tar.xz
62+
63+
cd "$BUILD_DIR"
64+
65+
# Configure with relaxed flags
66+
CFLAGS="-O2 -fPIC -fcommon -Wno-error=array-parameter -Wno-error=stringop-overflow -Wno-error" \
67+
../glibc-$GLIBC_VERSION/configure --prefix="$PREFIX"
68+
69+
# Build
70+
make -j"$(nproc)" CFLAGS="$CFLAGS"
71+
72+
# Install
73+
make install
74+
75+
# Check
76+
"$PREFIX/lib/ld-2.29.so" --version || true
77+
"$PREFIX/lib/libc.so.6" --version || true

backends/qualcomm/scripts/download_qnn_sdk.py

Lines changed: 19 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -254,123 +254,23 @@ def _extract_tar(archive_path: pathlib.Path, prefix: str, target_dir: pathlib.Pa
254254
GLIBC_REEXEC_GUARD = "QNN_GLIBC_REEXEC"
255255

256256

257-
def _parse_ver_tuple(s: str) -> Tuple[int, int]:
258-
parts = re.findall(r"\d+", s)
259-
return (int(parts[0]), int(parts[1])) if len(parts) >= 2 else (0, 0)
260-
261-
262-
def _detect_glibc_version() -> Optional[Tuple[int, int]]:
263-
for path in REQUIRED_LIBC_LIBS:
264-
try:
265-
out = subprocess.check_output([path, "--version"], stderr=subprocess.STDOUT)
266-
first = out.decode(errors="ignore").split("\n", 1)[0]
267-
m = re.search(r"version\s+(\d+\.\d+)", first, re.IGNORECASE)
268-
if m:
269-
vt = _parse_ver_tuple(m.group(1))
270-
logger.info("[glibc] Found %s version %s", path, vt)
271-
return vt
272-
except Exception as e:
273-
logger.info("[glibc] Skipped %s (%s)", path, e)
274-
return None
275-
276-
277-
def _install_glibc_234():
278-
"""Download and build glibc GLIBC_VERSION into /tmp/glibc-{GLIBC_VERSION} if missing."""
279-
if GLIBC_LOADER.exists():
280-
logger.info("[glibc] Already installed at %s", GLIBC_ROOT)
281-
return
282-
283-
logger.info(f"[glibc] Installing glibc {GLIBC_VERSION} into %s ...", GLIBC_ROOT)
284-
# url = "https://ftp.gnu.org/gnu/libc/glibc-2.34.tar.xz"
285-
# url = "https://ftp.gnu.org/gnu/libc/glibc-2.36.tar.xz"
286-
url = f"https://ftp.gnu.org/gnu/libc/glibc-{GLIBC_VERSION}.tar.xz"
257+
def _check_tmp_glibc() -> bool:
258+
"""Check if glibc in /tmp was installed correctly and log its version."""
259+
libc_path = pathlib.Path(f"/tmp/glibc-{GLIBC_VERSION}/lib/libc.so.6")
260+
if not libc_path.exists():
261+
logger.error("[glibc] Expected glibc at %s but file not found", libc_path)
262+
return False
287263

288-
with tempfile.TemporaryDirectory() as tmpdir:
289-
tarball = pathlib.Path(tmpdir) / f"glibc-{GLIBC_VERSION}.tar.xz"
290-
logger.info("[glibc] Downloading %s", url)
291-
urllib.request.urlretrieve(url, tarball)
292-
logger.info("[glibc] Downloaded %s", tarball)
293-
294-
logger.info("[glibc] Extracting source...")
295-
with tarfile.open(tarball, "r:xz") as tf:
296-
tf.extractall(path=tmpdir)
297-
298-
build_dir = pathlib.Path(tmpdir) / "glibc-build"
299-
os.makedirs(build_dir, exist_ok=True)
300-
301-
logger.info("[glibc] Configuring build...")
302-
env = os.environ.copy()
303-
304-
# Remove LD_LIBRARY_PATH to satisfy configure checks
305-
env.pop("LD_LIBRARY_PATH", None)
306-
307-
# Allow warnings (disable -Werror promoted by newer GCC)
308-
# Add -fcommon to avoid "multiple definition" issues on some glibc versions
309-
env["CFLAGS"] = (
310-
"-O2 -fPIC -fcommon "
311-
"-Wno-error=array-parameter "
312-
"-Wno-error=stringop-overflow "
313-
"-Wno-error"
314-
)
315-
env["CC"] = "gcc"
316-
317-
# Configure
318-
cmd = [f"../glibc-{GLIBC_VERSION}/configure", f"--prefix={GLIBC_ROOT}"]
319-
logger.info("[glibc] Running: %s", " ".join(cmd))
320-
subprocess.check_call(cmd, cwd=build_dir, env=env)
321-
322-
# Build
323-
cmd = ["make", "-j", str(os.cpu_count()), "CFLAGS=" + env["CFLAGS"]]
324-
logger.info("[glibc] Running: %s", " ".join(cmd))
325-
subprocess.check_call(cmd, cwd=build_dir, env=env)
326-
327-
# Install
328-
cmd = ["make", "install"]
329-
logger.info("[glibc] Running: %s", " ".join(cmd))
330-
logger.info(f"[glibc] Installing into /tmp/glibc-{GLIBC_VERSION} ...")
331-
subprocess.check_call(cmd, cwd=build_dir, env=env)
332-
logger.info("[glibc] Installation complete")
333-
334-
if GLIBC_LOADER.exists():
335-
logger.info(
336-
f"[glibc] Successfully installed glibc {GLIBC_VERSION} at %s", GLIBC_ROOT
337-
)
338-
else:
339-
logger.error(
340-
"[glibc] Install finished but loader not found at %s", GLIBC_LOADER
264+
try:
265+
out = subprocess.check_output(
266+
[str(libc_path), "--version"], stderr=subprocess.STDOUT
341267
)
342-
343-
344-
def _reexec_with_new_glibc_if_needed(min_required=(2, 29)):
345-
if os.environ.get(GLIBC_REEXEC_GUARD) == "1":
346-
logger.debug("[glibc] Already re-executed once; skipping loop.")
347-
return
348-
349-
vt = _detect_glibc_version()
350-
if vt is None:
351-
logger.warn("[glibc] Could not detect system glibc version.")
352-
elif vt < min_required:
353-
logger.warn("[glibc] System glibc %s < required %s", vt, min_required)
354-
else:
355-
logger.info("[glibc] System glibc %s >= required %s", vt, min_required)
356-
return
357-
358-
_install_glibc_234()
359-
if not GLIBC_LOADER.exists():
360-
logger.error("[glibc] Loader still missing at %s", GLIBC_LOADER)
361-
return
362-
363-
argv = [
364-
str(GLIBC_LOADER),
365-
"--library-path",
366-
str(GLIBC_LIBDIR),
367-
sys.executable,
368-
] + sys.argv
369-
env = os.environ.copy()
370-
env[GLIBC_REEXEC_GUARD] = "1"
371-
372-
logger.warn("[glibc] Re-executing under new loader: %s", argv)
373-
os.execvpe(str(GLIBC_LOADER), argv, env)
268+
first_line = out.decode(errors="ignore").split("\n", 1)[0]
269+
logger.info("[glibc] Found custom glibc at %s: %s", libc_path, first_line)
270+
return True
271+
except Exception as e:
272+
logger.error("[glibc] Failed to run %s --version: %s", libc_path, e)
273+
return False
374274

375275

376276
####################
@@ -575,7 +475,10 @@ def install_qnn_sdk() -> bool:
575475
"""
576476
logger.info("[QNN] Starting SDK installation")
577477
# Re-exec with glibc 2.36 if needed.
578-
_reexec_with_new_glibc_if_needed()
478+
# Just check that pre-installed glibc is present and valid
479+
if not _check_tmp_glibc():
480+
logger.error("[glibc] Pre-installed glibc check failed. Exiting early.")
481+
return False
579482

580483
if _ensure_libcxx_stack():
581484
if _ensure_qnn_sdk_lib():

0 commit comments

Comments
 (0)