-
Notifications
You must be signed in to change notification settings - Fork 1k
Add git submodule update to build_backend.py #3190
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,23 +79,32 @@ def _create_build_metadata(): | |
|
|
||
| def _compile_jit_cache(output_dir: Path, verbose: bool = True): | ||
| """Compile AOT modules using flashinfer.aot functions directly.""" | ||
| # Get the project root directory | ||
| project_root = Path(__file__).parent.parent | ||
|
|
||
| # Ensure 3rdparty submodules are populated (may be empty in CI Docker images) | ||
| import subprocess | ||
|
|
||
| subprocess.run( | ||
| ["git", "submodule", "update", "--init", "--recursive"], | ||
| cwd=str(project_root), | ||
| check=True, | ||
| ) | ||
|
Comment on lines
+85
to
+92
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π§© Analysis chainπ Script executed: #!/bin/bash
set -euo pipefail
echo "1) Verify current code uses PATH-only git invocation"
rg -n 'subprocess\.run\(\s*\["git",\s*"submodule"' flashinfer-jit-cache/build_backend.py -n -C2 || true
echo
echo "2) Demonstrate git submodule fails outside a git repo"
tmpdir="$(mktemp -d)"
if git -C "$tmpdir" submodule update --init --recursive >"$tmpdir/out.log" 2>&1; then
echo "Unexpected: command succeeded outside a git repo"
exit 1
else
echo "Expected failure:"
sed -n '1,3p' "$tmpdir/out.log"
fiRepository: flashinfer-ai/flashinfer Length of output: 263 π Script executed: cat -n flashinfer-jit-cache/build_backend.py | sed -n '80,95p'Repository: flashinfer-ai/flashinfer Length of output: 801 π Script executed: # Check where _compile_jit_cache is called
rg -n '_compile_jit_cache' flashinfer-jit-cache/ --type py -B2 -A2
# Check if there are any other references to git in the build
echo "---"
echo "Other git references in build files:"
rg -n 'git' flashinfer-jit-cache/build_backend.py --type pyRepository: flashinfer-ai/flashinfer Length of output: 1547 π Script executed: # Check how get_git_version handles non-git scenarios
rg -n 'def get_git_version' --type py -A10
# Check if 3rdparty is included in sdist
ls -la flashinfer-jit-cache/3rdparty/ 2>/dev/null | head -20 || echo "3rdparty dir check failed"
# Check the actual directory structure
find flashinfer-jit-cache -maxdepth 2 -type d -name "3rdparty" -o -name ".gitmodules"Repository: flashinfer-ai/flashinfer Length of output: 540 π Script executed: # Read full get_git_version function
cat build_utils.py | sed -n '24,50p'
# Check .gitmodules
if [ -f .gitmodules ]; then
echo ".gitmodules exists:"
cat .gitmodules
else
echo "No .gitmodules found"
fi
# Check 3rdparty structure
ls -la 3rdparty/ 2>/dev/null | head -20 || echo "3rdparty not found at root"Repository: flashinfer-ai/flashinfer Length of output: 1254 Guard submodule update for non-git sources and avoid PATH-only executable lookup. At lines 88β92,
The codebase already detects git repo existence at lines 57β59. Apply the same pattern here: Suggested fix def _compile_jit_cache(output_dir: Path, verbose: bool = True):
"""Compile AOT modules using flashinfer.aot functions directly."""
# Get the project root directory
project_root = Path(__file__).parent.parent
# Ensure 3rdparty submodules are populated (may be empty in CI Docker images)
+ import shutil
import subprocess
- subprocess.run(
- ["git", "submodule", "update", "--init", "--recursive"],
- cwd=str(project_root),
- check=True,
- )
+ git_dir = project_root / ".git"
+ if git_dir.exists():
+ git_bin = shutil.which("git")
+ if git_bin is None:
+ raise RuntimeError("git is required to initialize submodules in a git checkout")
+ subprocess.run(
+ [git_bin, "submodule", "update", "--init", "--recursive"],
+ cwd=str(project_root),
+ check=True,
+ )
+ else:
+ required = [
+ project_root / "3rdparty" / "cutlass",
+ project_root / "3rdparty" / "spdlog",
+ project_root / "3rdparty" / "cccl",
+ ]
+ missing = [str(p) for p in required if not p.exists()]
+ if missing:
+ raise RuntimeError(
+ "Missing required 3rdparty dependencies outside git checkout: "
+ + ", ".join(missing)
+ )π§° Toolsπͺ Ruff (0.15.12)[error] 89-89: Starting a process with a partial executable path (S607) π€ Prompt for AI Agents |
||
|
|
||
| # Ensure flashinfer/data/ symlinks exist (normally created by the main | ||
| # package's build_backend, but jit-cache builds may not install the main | ||
| # package first). Use importlib to avoid name collision with this file. | ||
| import importlib.util | ||
|
|
||
| spec = importlib.util.spec_from_file_location( | ||
| "main_build_backend", Path(__file__).parent.parent / "build_backend.py" | ||
| "main_build_backend", project_root / "build_backend.py" | ||
| ) | ||
| main_build_backend = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(main_build_backend) | ||
| main_build_backend._create_data_dir(use_symlinks=True) | ||
|
|
||
| from flashinfer import aot | ||
|
|
||
| # Get the project root directory | ||
| project_root = Path(__file__).parent.parent | ||
|
|
||
| # Set up build directory | ||
| build_dir = project_root / "build" / "aot" | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running
git submodule updateunconditionally will cause the build to fail when the source is not a git repository (e.g., when installing from a source distribution or a zip archive). It is important to check for the existence of the.gitdirectory before executing git commands. Additionally, wrapping the call in a try-except block ensures that the build doesn't crash if thegitexecutable is missing from the environment.