Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .pfnci/wheel-windows/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ $fastrlock_version = @(python -c "import dist_config; print(dist_config.FASTRLOC
echo ">> Updating packaging utilities..."
RunOrDie python -m pip install -U setuptools pip
echo ">> Installing dependences for wheel build..."
RunOrDie python -m pip install -U -r ./requirements.txt wheel Cython==${cython_version} fastrlock==${fastrlock_version} pytest
RunOrDie python -m pip install -U -r ./requirements.txt setuptools-scm wheel Cython==${cython_version} fastrlock==${fastrlock_version} pytest
echo ">> Packages installed:"
RunOrDie python -m pip list

Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ For Linux builds, you can use the ``build.sh`` shell script that wraps the Build
# Prepare source tree
git clone --recursive https://github.com/cupy/cupy.git

# Build & verify a sdist (using Python 3.10)
./build.sh sdist 3.10
# Build & verify a sdist, using Python 3.12, version CuPy package as v14.5.0
./build.sh sdist 3.12 14.5.0

# Build & verify a wheel for CUDA 11.0 + Python 3.8
./build.sh 11.0 3.8
# Build & verify a wheel for CUDA 12.x + Python 3.11, version CuPy package as v13.3.0
./build.sh 12.x 3.11 13.3.0

For Windows, or if you need some more detailed configuration, see the sections below to manually run the tool.

Expand Down
11 changes: 6 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

CUDA="${1}"
PYTHON="${2}"
VERSION="${3}"

# Set DIST_OPTIONS and DIST_FILE_NAME
# Set DIST_OPTIONS (for build/verify) and DIST_FILE_NAME (for verify)
case ${CUDA} in
sdist )
DIST_OPTIONS="--target sdist --python ${PYTHON}"
eval $(./get_dist_info.py --target sdist --source cupy)
DIST_OPTIONS="--target sdist --version ${VERSION} --python ${PYTHON}"
eval $(./get_dist_info.py --target sdist --source cupy --version ${VERSION})
;;
* )
DIST_OPTIONS="--target wheel-linux --python ${PYTHON} --cuda ${CUDA}"
eval $(./get_dist_info.py --target wheel-linux --source cupy --cuda ${CUDA} --python ${PYTHON})
DIST_OPTIONS="--target wheel-linux --version "${VERSION}" --python ${PYTHON} --cuda ${CUDA}"
eval $(./get_dist_info.py --target wheel-linux --source cupy --version ${VERSION} --cuda ${CUDA} --python ${PYTHON})
;;
esac

Expand Down
2 changes: 1 addition & 1 deletion builder/setup_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ for VERSION in ${PYTHON_VERSIONS}; do \
echo "Installing libraries on Python ${VERSION}..."
pyenv global ${VERSION}
pip install -U pip setuptools
pip install "Cython==${CYTHON_VERSION}" "fastrlock==${FASTRLOCK_VERSION}" wheel auditwheel build tomli tomli-w
pip install "Cython==${CYTHON_VERSION}" "fastrlock==${FASTRLOCK_VERSION}" setuptools-scm wheel auditwheel build tomli tomli-w
done

# The last version installed will be used to run the builder agent.
Expand Down
30 changes: 24 additions & 6 deletions dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
) # NOQA
from dist_utils import (
get_system_cuda_version,
get_version_from_source_tree,
sdist_name,
wheel_linux_platform_tag,
wheel_name,
Expand Down Expand Up @@ -124,6 +123,13 @@ def rename_project(src: str, name: str) -> None:
tomli_w.dump(pp, f)


def get_setuptools_scm_env_name(package_name: str) -> str:
"""Returns the environment variable name for setuptools_scm which is used
to override the version of the package."""
norm_name = package_name.replace('-', '_').upper()
return f'SETUPTOOLS_SCM_PRETEND_VERSION_FOR_{norm_name}'


class _ControllerArgs(argparse.Namespace):
action: Literal['build', 'verify']
target: Literal['sdist', 'wheel-linux', 'wheel-win']
Expand All @@ -133,6 +139,7 @@ class _ControllerArgs(argparse.Namespace):
push: bool
rmi: bool
source: str | None
version: str | None
output: str
dist: str | None
test: list[str]
Expand Down Expand Up @@ -175,6 +182,9 @@ def parse_args() -> _ControllerArgs:
'--source', type=str,
help='[build] path to the CuPy source tree; '
'must be a clean checkout')
parser.add_argument(
'--version', type=str,
help='version of the package')
parser.add_argument(
'--output', type=str, default='.',
help='[build] path to the directory to place '
Expand All @@ -196,16 +206,17 @@ def main(self) -> None:

if args.action == 'build':
assert args.source is not None
assert args.version is not None
with log_group('Build'):
if args.target == 'wheel-win':
assert args.cuda is not None, 'CUDA version unspecified'
self.build_windows(
args.target, args.cuda, args.python,
args.target, args.version, args.cuda, args.python,
args.source, args.output)
else:
# For sdist build, args.cuda can be None.
self.build_linux(
args.target, args.cuda, args.python,
args.target, args.version, args.cuda, args.python,
args.source, args.output, args.dry_run, args.push,
args.rmi)
elif args.action == 'verify':
Expand Down Expand Up @@ -363,6 +374,7 @@ def _ensure_compatible_branch(version: str) -> None:
def build_linux(
self,
target: str,
version: str,
cuda_version: str | None,
python_version: str,
source: str,
Expand All @@ -373,7 +385,6 @@ def build_linux(
) -> None:
"""Build a single wheel distribution for Linux."""

version = get_version_from_source_tree(source)
self._ensure_compatible_branch(version)

if target == 'wheel-linux':
Expand Down Expand Up @@ -444,7 +455,12 @@ def build_linux(
]

# Environmental variables to pass to builder
setup_args = ['--env', 'CUPY_LONG_DESCRIPTION_PATH=../description.rst']
setup_args = [
'--env',
f'{get_setuptools_scm_env_name(package_name)}={version}',
'--env',
'CUPY_LONG_DESCRIPTION_PATH=../description.rst',
]
if target == 'wheel-linux':
setup_args += [
'--env',
Expand Down Expand Up @@ -573,6 +589,7 @@ def _check_windows_environment(
def build_windows(
self,
target: str,
version: str,
cuda_version: str,
python_version: str,
source: str,
Expand All @@ -589,7 +606,6 @@ def build_windows(
if target != 'wheel-win':
raise ValueError('unknown target')

version = get_version_from_source_tree(source)
self._ensure_compatible_branch(version)

log(
Expand All @@ -615,6 +631,8 @@ def build_windows(

# Environmental variables to pass to builder
agent_args += [
'--env',
f'{get_setuptools_scm_env_name(package_name)}={version}',
'--env',
'CUPY_INSTALL_LONG_DESCRIPTION_PATH=../description.rst',
'--env',
Expand Down
8 changes: 0 additions & 8 deletions dist_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ def wheel_name(
)


def get_version_from_source_tree(source_tree: str) -> str:
version_file_path = f'{source_tree}/cupy/_version.py'
exec_locals: dict[str, str] = {}
with open(version_file_path, encoding='UTF-8') as f:
exec(f.read(), None, exec_locals)
return exec_locals['__version__']


def get_system_cuda_version(cudart_name: str = 'cudart') -> int | None:
filename = ctypes.util.find_library(cudart_name)
if filename is None:
Expand Down
12 changes: 7 additions & 5 deletions get_dist_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
WHEEL_WINDOWS_CONFIGS,
) # NOQA
from dist_utils import (
get_version_from_source_tree,
sdist_name,
wheel_linux_platform_tag,
wheel_name,
Expand All @@ -20,6 +19,7 @@
class _DistInfoArgs(argparse.Namespace):
target: Literal['sdist', 'wheel-linux', 'wheel-win']
source: str
version: str
cuda: str
python: str

Expand All @@ -37,6 +37,9 @@ def parse_args() -> _DistInfoArgs:
parser.add_argument(
'--source', type=str, required=True,
help='path to the CuPy source tree; must be a clean checkout')
parser.add_argument(
'--version', type=str, required=True,
help='version of the package')

# Options specific for wheels:
parser.add_argument(
Expand All @@ -50,19 +53,18 @@ def parse_args() -> _DistInfoArgs:

def main(self) -> None:
args = self.parse_args()
version = get_version_from_source_tree(args.source)
if args.target == 'wheel-linux':
pkg_name = WHEEL_LINUX_CONFIGS[args.cuda]['name']
arch = WHEEL_LINUX_CONFIGS[args.cuda].get('arch', 'x86_64')
filename = wheel_name(
pkg_name, version, args.python,
pkg_name, args.version, args.python,
wheel_linux_platform_tag(arch, True))
elif args.target == 'wheel-win':
pkg_name = WHEEL_WINDOWS_CONFIGS[args.cuda]['name']
filename = wheel_name(pkg_name, version, args.python, 'win_amd64')
filename = wheel_name(pkg_name, args.version, args.python, 'win_amd64')
elif args.target == 'sdist':
pkg_name = 'cupy'
filename = sdist_name(pkg_name, version)
filename = sdist_name(pkg_name, args.version)
else:
raise AssertionError('Unreachable')
print(f'DIST_FILE_NAME="{filename}"')
Expand Down
Loading