-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] extend
build-commit
workflow to support different compile-ar…
…chs (#3459) # Overview This PR extends the build commit workflow to also support building for ARM architectures. The current workflow only built for x86. ## Limitations - We are building using the `buildjet` service. - Buildjet provides ARM machines. However, their ARM machines only run Ubuntu 22.04. - Ubuntu 22.04 runs glibc2.34. - glibc is forwards-compatible, but *not* backwards compatible. - This means that whenever you are running the built wheel, you must be running it on a machine which contains glibc2.34 or greater. Installs of the wheel will fail on platforms which contain older versions of glibc. (Note that most AWS AMIs contain older versions of glibc). ## Notes The storage structure of the wheels in AWS S3 is as below: ```txt github-actions-artifacts-bucket |- builds |- ${{ GITHUB.SHA }} |- ${{ WHEEL_NAME_FOR_X86 }} |- ${{ WHEEL_NAME_FOR_ARM }} ```
- Loading branch information
Raunak Bhagat
authored
Dec 4, 2024
1 parent
83470e0
commit 5ce91c8
Showing
5 changed files
with
158 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
BUCKET_NAME = "github-actions-artifacts-bucket" | ||
WHEEL_SUFFIX = ".whl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
Given a commit hash and a "platform substring", prints the wheelname of the wheel (if one exists) to stdout. | ||
# Example | ||
```bash | ||
COMMIT_HASH="abcdef0123456789" | ||
PLATFORM_SUBSTRING="x86" | ||
WHEELNAME=$(python get_wheel_name_from_s3.py $COMMIT_HASH $PLATFORM_SUBSTRING) | ||
echo $WHEELNAME | ||
# Will echo the wheelname if a wheel exists that matches the platform substring. | ||
# Otherwise, will echo nothing. | ||
``` | ||
""" | ||
|
||
import sys | ||
from pathlib import Path | ||
|
||
import boto3 | ||
import wheellib | ||
|
||
if __name__ == "__main__": | ||
commit_hash = sys.argv[1] | ||
platform_substring = sys.argv[2] | ||
|
||
s3 = boto3.client("s3") | ||
response = s3.list_objects_v2(Bucket="github-actions-artifacts-bucket", Prefix=f"builds/{commit_hash}/") | ||
matches = [] | ||
for content in response.get("Contents", []): | ||
wheelname = Path(content["Key"]).name | ||
platform_tag = wheellib.get_platform_tag(wheelname) | ||
if platform_substring in platform_tag: | ||
matches.append(wheelname) | ||
|
||
if len(matches) > 1: | ||
raise Exception( | ||
f"Multiple wheels found that match the given platform substring: {platform_substring}; expected just 1" | ||
) | ||
|
||
try: | ||
print(next(iter(matches))) | ||
except StopIteration: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import argparse | ||
from pathlib import Path | ||
|
||
import boto3 | ||
import constants | ||
import wheellib | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--commit-hash", required=True) | ||
parser.add_argument("--platform-substring", required=True, choices=["x86", "aarch", "arm"]) | ||
parser.add_argument("--path-to-wheel-dir", required=True) | ||
args = parser.parse_args() | ||
|
||
commit_hash = args.commit_hash | ||
platform_substring = args.platform_substring | ||
path_to_wheel_dir = Path(args.path_to_wheel_dir) | ||
|
||
assert path_to_wheel_dir.exists(), f"Path to wheel directory does not exist: {path_to_wheel_dir}" | ||
wheelpaths = iter(filepath for filepath in path_to_wheel_dir.iterdir() if filepath.suffix == constants.WHEEL_SUFFIX) | ||
|
||
def f(wheelpath: Path) -> bool: | ||
platform_tag = wheellib.get_platform_tag(wheelpath.name) | ||
return platform_substring in platform_tag | ||
|
||
filtered_wheelpaths: list[Path] = list(filter(f, wheelpaths)) | ||
|
||
length = len(filtered_wheelpaths) | ||
if length == 0: | ||
raise RuntimeError(f"No wheels found that match the given platform substring: {platform_substring}; expected 1") | ||
elif length > 1: | ||
raise RuntimeError( | ||
f"""Multiple wheels found that match the given platform substring: {platform_substring}; expected just 1 | ||
Wheels available: {wheelpaths}""" | ||
) | ||
[wheelpath] = filtered_wheelpaths | ||
s3 = boto3.client("s3") | ||
destination = Path("builds") / commit_hash / wheelpath.name | ||
s3.upload_file( | ||
Filename=wheelpath, | ||
Bucket=constants.BUCKET_NAME, | ||
Key=str(destination), | ||
ExtraArgs={"ACL": "public-read"}, | ||
) | ||
print(wheelpath.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from packaging.utils import parse_wheel_filename | ||
|
||
|
||
def get_platform_tag(wheelname: str) -> str: | ||
distribution, version, build_tag, tags = parse_wheel_filename(wheelname) | ||
assert len(tags) == 1, "Multiple tags found" | ||
return next(iter(tags)).platform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters