Skip to content

Commit

Permalink
Merge pull request #17799 from hawkinsp:build
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 568710854
  • Loading branch information
jax authors committed Sep 27, 2023
2 parents f441385 + cf28e2c commit 82d9b7f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/wheel_win_x64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: |
python -m pip install -r build/test-requirements.txt
"C:\\msys64\\;C:\\msys64\\usr\\bin\\;" >> $env:GITHUB_PATH
python.exe build\build.py --bazel_options=--color=yes
python.exe build\build.py --bazel_options=--color=yes --verbose
- uses: actions/upload-artifact@v3
with:
Expand Down
39 changes: 22 additions & 17 deletions build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,10 @@
import subprocess
import sys
import textwrap
import urllib
import urllib.request
import logging

# pylint: disable=g-import-not-at-top
if hasattr(urllib, "urlretrieve"):
urlretrieve = urllib.urlretrieve
else:
import urllib.request
urlretrieve = urllib.request.urlretrieve

if hasattr(shutil, "which"):
which = shutil.which
else:
from distutils.spawn import find_executable as which
# pylint: enable=g-import-not-at-top
logger = logging.getLogger(__name__)


def is_windows():
Expand All @@ -50,10 +40,14 @@ def is_windows():

def shell(cmd):
try:
logger.info("shell(): %s", cmd)
output = subprocess.check_output(cmd)
except subprocess.CalledProcessError as e:
logger.info("subprocess raised: %s", e)
if e.output: print(e.output)
raise
except Exception as e:
logger.info("subprocess raised: %s", e)
return output.decode("UTF-8").strip()


Expand Down Expand Up @@ -153,8 +147,9 @@ def progress(block_count, block_size, total_size):
package.file, "#" * progress_chars,
"." * (num_chars - progress_chars), int(progress * 100.0)))

tmp_path, _ = urlretrieve(uri, None,
progress if sys.stdout.isatty() else None)
tmp_path, _ = urllib.request.urlretrieve(
uri, None, progress if sys.stdout.isatty() else None
)
sys.stdout.write("\n")

# Verify that the downloaded Bazel binary has the expected SHA256.
Expand Down Expand Up @@ -185,7 +180,7 @@ def get_bazel_paths(bazel_path_flag):
can be None. The resulting iterator is lazy and potentially has a side
effects."""
yield bazel_path_flag
yield which("bazel")
yield shutil.which("bazel")
yield download_and_verify_bazel()


Expand All @@ -211,7 +206,7 @@ def get_bazel_path(bazel_path_flag):
def get_bazel_version(bazel_path):
try:
version_output = shell([bazel_path, "--version"])
except subprocess.CalledProcessError:
except (subprocess.CalledProcessError, OSError):
return None
match = re.search(r"bazel *([0-9\\.]+)", version_output)
if match is None:
Expand Down Expand Up @@ -344,6 +339,11 @@ def main():
cwd = os.getcwd()
parser = argparse.ArgumentParser(
description="Builds jaxlib from source.", epilog=EPILOG)
add_boolean_argument(
parser,
"verbose",
default=False,
help_str="Should we produce verbose debugging output?")
parser.add_argument(
"--bazel_path",
help="Path to the Bazel binary to use. The default is to find bazel via "
Expand Down Expand Up @@ -464,6 +464,10 @@ def main():
help_str="If true, writes a .bazelrc file but does not build jaxlib.")
args = parser.parse_args()

logging.basicConfig()
if args.verbose:
logger.setLevel(logging.DEBUG)

if is_windows() and args.enable_cuda:
if args.cuda_version is None:
parser.error("--cuda_version is needed for Windows CUDA build.")
Expand Down Expand Up @@ -504,6 +508,7 @@ def main():
print(f"NumPy version: {numpy_version}")
check_package_is_installed(python_bin_path, "wheel")
check_package_is_installed(python_bin_path, "build")
check_package_is_installed(python_bin_path, "setuptools")

print("MKL-DNN enabled: {}".format("yes" if args.enable_mkl_dnn else "no"))
print(f"Target CPU: {wheel_cpu}")
Expand Down
1 change: 1 addition & 0 deletions build/test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ portpicker
pytest-xdist
wheel
rich
setuptools

0 comments on commit 82d9b7f

Please sign in to comment.