Skip to content

Commit 51010ba

Browse files
committed
Build Mac wheels in CI
1 parent 707ea13 commit 51010ba

File tree

5 files changed

+99
-33
lines changed

5 files changed

+99
-33
lines changed

.github/workflows/linux_wheel.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
needs: generate-matrix
3939
strategy:
4040
fail-fast: false
41-
name: Build and Upload wheel
41+
name: Build and Upload Linux wheel
4242
uses: pytorch/test-infra/.github/workflows/build_wheels_linux.yml@main
4343
with:
4444
repository: pytorch/torchcodec

.github/workflows/macos_wheel.yaml

+63-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and test MacOS
1+
name: Build and test MacOS wheels
22

33
on:
44
pull_request:
@@ -24,6 +24,35 @@ defaults:
2424
shell: bash -l -eo pipefail {0}
2525

2626
jobs:
27+
generate-matrix:
28+
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
29+
with:
30+
package-type: wheel
31+
os: macos-arm64
32+
test-infra-repository: pytorch/test-infra
33+
test-infra-ref: main
34+
with-xpu: disable
35+
with-rocm: disable
36+
with-cuda: disable
37+
build:
38+
needs: generate-matrix
39+
strategy:
40+
fail-fast: false
41+
name: Build and Upload Mac wheel
42+
uses: pytorch/test-infra/.github/workflows/build_wheels_macos.yml@main
43+
with:
44+
repository: pytorch/torchcodec
45+
ref: ""
46+
test-infra-repository: pytorch/test-infra
47+
test-infra-ref: main
48+
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
49+
post-script: packaging/post_build_script.sh
50+
smoke-test-script: packaging/fake_smoke_test.py
51+
runner-type: macos-m1-stable
52+
package-name: torchcodec
53+
trigger-event: ${{ github.event_name }}
54+
env-var-script: packaging/wheel_env.sh
55+
2756
install-and-test:
2857
runs-on: macos-m1-stable
2958
strategy:
@@ -32,7 +61,12 @@ jobs:
3261
python-version: ['3.9']
3362
ffmpeg-version-for-tests: ['4.4.2', '5.1.2', '6.1.1', '7.0.1']
3463
if: ${{ always() }}
64+
needs: build
3565
steps:
66+
- uses: actions/download-artifact@v3
67+
with:
68+
name: pytorch_torchcodec__${{ matrix.python-version }}_cpu_
69+
path: pytorch/torchcodec/dist/
3670
- name: Setup conda env
3771
uses: conda-incubator/setup-miniconda@v3
3872
with:
@@ -45,19 +79,14 @@ jobs:
4579
- name: Install PyTorch
4680
run: |
4781
python -m pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu
82+
- name: Install torchcodec from the wheel
83+
run: |
84+
wheel_path=`find pytorch/torchcodec/dist -type f -name "*.whl"`
85+
echo Installing $wheel_path
86+
python -m pip install $wheel_path -vvv
87+
4888
- name: Check out repo
4989
uses: actions/checkout@v3
50-
- name: Install compile from source dependencies
51-
run: |
52-
conda install cmake pkg-config -c conda-forge
53-
- name: Install test dependencies
54-
run: |
55-
python -m pip install --pre torchvision --index-url https://download.pytorch.org/whl/nightly/cpu
56-
# Ideally we would find a way to get those dependencies from pyproject.toml
57-
python -m pip install numpy pytest pillow
58-
- name: Install torchcodec from source, building against non-GPL FFmpeg
59-
run: |
60-
BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1 pip install -e ".[dev]" --no-build-isolation
6190
- name: Install ffmpeg, post build
6291
run: |
6392
# Ideally we would have checked for that before installing the wheel,
@@ -69,9 +98,30 @@ jobs:
6998
7099
conda install "ffmpeg=${{ matrix.ffmpeg-version-for-tests }}" -c conda-forge
71100
ffmpeg -version
101+
102+
- name: Install test dependencies
103+
run: |
104+
python -m pip install --pre torchvision --index-url https://download.pytorch.org/whl/nightly/cpu
105+
# Ideally we would find a way to get those dependencies from pyproject.toml
106+
python -m pip install numpy pytest pillow
107+
108+
- name: Delete the src/ folder just for fun
109+
run: |
110+
# The only reason we checked-out the repo is to get access to the
111+
# tests. We don't care about the rest. Out of precaution, we delete
112+
# the src/ folder to be extra sure that we're running the code from
113+
# the installed wheel rather than from the source.
114+
# This is just to be extra cautious and very overkill because a)
115+
# there's no way the `torchcodec` package from src/ can be found from
116+
# the PythonPath: the main point of `src/` is precisely to protect
117+
# against that and b) if we ever were to execute code from
118+
# `src/torchcodec`, it would fail loudly because the built .so files
119+
# aren't present there.
120+
rm -r src/
121+
ls
72122
- name: Smoke test
73123
run: |
74124
python test/decoders/manual_smoke_test.py
75125
- name: Run Python tests
76126
run: |
77-
pytest test -vvv
127+
pytest test

packaging/check_glibcxx.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@
3838

3939
MAX_ALLOWED = (3, 4, 19)
4040

41+
libraries = sys.argv[1].split("\n")
4142
all_symbols = set()
42-
for line in sys.argv[1].split("\n"):
43+
for line in libraries:
4344
# We search for GLIBCXX_major.minor.micro
4445
if match := re.search(r"GLIBCXX_\d+\.\d+\.\d+", line):
4546
all_symbols.add(match.group(0))
4647

4748
if not all_symbols:
48-
raise ValueError("No GLIBCXX symbols found. Something is wrong.")
49+
raise ValueError(f"No GLIBCXX symbols found in {libraries}. Something is wrong.")
4950

5051
all_versions = (symbol.split("_")[1].split(".") for symbol in all_symbols)
5152
all_versions = (tuple(int(v) for v in version) for version in all_versions)

packaging/post_build_script.sh

+31-17
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,52 @@
11
#!/bin/bash
22

3+
set -eux
4+
35
source packaging/helpers.sh
46

57
wheel_path=$(pwd)/$(find dist -type f -name "*.whl")
68
echo "Wheel content:"
79
unzip -l $wheel_path
810

11+
unamestr=$(uname)
12+
if [[ "$unamestr" == 'Linux' ]]; then
13+
ext="so"
14+
elif [[ "$unamestr" == 'Darwin' ]]; then
15+
ext="dylib"
16+
else
17+
echo "Unknown operating system: $unamestr"
18+
exit 1
19+
fi
20+
921
for ffmpeg_major_version in 4 5 6 7; do
10-
assert_in_wheel $wheel_path torchcodec/libtorchcodec${ffmpeg_major_version}.so
22+
assert_in_wheel $wheel_path torchcodec/libtorchcodec${ffmpeg_major_version}.${ext}
1123
done
12-
assert_not_in_wheel $wheel_path libtorchcodec.so
24+
assert_not_in_wheel $wheel_path libtorchcodec.${ext}
1325

14-
for ffmpeg_so in libavcodec.so libavfilter.so libavformat.so libavutil.so libavdevice.so ; do
15-
assert_not_in_wheel $wheel_path $ffmpeg_so
26+
for ffmpeg_ext in libavcodec.${ext} libavfilter.${ext} libavformat.${ext} libavutil.${ext} libavdevice.${ext} ; do
27+
assert_not_in_wheel $wheel_path $ffmpeg_ext
1628
done
1729

1830
assert_not_in_wheel $wheel_path "^test"
1931
assert_not_in_wheel $wheel_path "^doc"
2032
assert_not_in_wheel $wheel_path "^benchmarks"
2133
assert_not_in_wheel $wheel_path "^packaging"
2234

23-
# See invoked python script below for details about this check.
24-
extracted_wheel_dir=$(mktemp -d)
25-
unzip -q $wheel_path -d $extracted_wheel_dir
26-
symbols_matches=$(find $extracted_wheel_dir | grep ".so$" | xargs objdump --syms | grep GLIBCXX_3.4.)
27-
python packaging/check_glibcxx.py "$symbols_matches"
28-
29-
echo "ls dist"
30-
ls dist
31-
32-
old="linux_x86_64"
33-
new="manylinux_2_17_x86_64.manylinux2014_x86_64"
34-
echo "Replacing ${old} with ${new} in wheel name"
35-
mv dist/*${old}*.whl $(echo dist/*${old}*.whl | sed "s/${old}/${new}/")
35+
if [[ "$unamestr" == 'Linux' ]]; then
36+
# See invoked python script below for details about this check.
37+
extracted_wheel_dir=$(mktemp -d)
38+
unzip -q $wheel_path -d $extracted_wheel_dir
39+
symbols_matches=$(find $extracted_wheel_dir | grep ".so$" | xargs objdump --syms | grep GLIBCXX_3.4.)
40+
python packaging/check_glibcxx.py "$symbols_matches"
41+
42+
echo "ls dist"
43+
ls dist
44+
45+
old="linux_x86_64"
46+
new="manylinux_2_17_x86_64.manylinux2014_x86_64"
47+
echo "Replacing ${old} with ${new} in wheel name"
48+
mv dist/*${old}*.whl $(echo dist/*${old}*.whl | sed "s/${old}/${new}/")
49+
fi
3650

3751
echo "ls dist"
3852
ls dist

packaging/wheel_env.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1

0 commit comments

Comments
 (0)