Always build libtorchcodec{ffmpeg_major}.so instead of libtorchcodec.so #114
Workflow file for this run
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
name: Unit Test | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
concurrency: | |
group: unit-test${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_number || github.ref }} | |
cancel-in-progress: true | |
defaults: | |
run: | |
shell: bash -l -eo pipefail {0} | |
jobs: | |
unit_tests: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ['3.8', '3.12'] | |
ffmpeg-version-for-tests: ['4.4.2', '5.1.2', '6.1.1', '7.0.1'] | |
steps: | |
- name: Check out repo | |
uses: actions/checkout@v3 | |
- name: Setup conda env | |
uses: conda-incubator/setup-miniconda@v2 | |
with: | |
auto-update-conda: true | |
miniconda-version: "latest" | |
activate-environment: test | |
python-version: ${{ matrix.python-version }} | |
- name: Update pip | |
run: python -m pip install --upgrade pip | |
- name: Install dependencies | |
run: | | |
python -m pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu | |
- name: Build and install torchcodec | |
run: | | |
if command -v "ffmpeg" &> /dev/null | |
then | |
echo "ffmpeg is installed, but it shouldn't! Exiting!!" | |
exit 1 | |
fi | |
# TODO: should we pass -DCMAKE_BUILD_TYPE=Debug here? That's what we | |
# do for the C++ tests. | |
python -m pip install -e ".[dev]" --no-build-isolation -vvv | |
# list the built so files, for debugging. | |
find src | grep ".so" | |
- name: Install ffmpeg, post build | |
run: | | |
conda install "ffmpeg=${{ matrix.ffmpeg-version-for-tests }}" -c conda-forge | |
ffmpeg -version | |
- name: Smoke test | |
run: | | |
python test/decoders/manual_smoke_test.py | |
# TODO: diff the output frame with its expeceted value | |
- name: Run Python tests | |
run: | | |
pytest test | |
- name: Build and run C++ tests | |
run: | | |
conda install pkg-config -c conda-forge | |
export BUILD_AGAINST_INSTALLED_FFMPEG=1 | |
# Why we need BUILD_AGAINST_INSTALLED_FFMPEG and pkg-config: | |
# The C++ tests decode x264 files which is not supported by our | |
# pre-built non-GPL FFmpeg libraries. Unfortunately, that's what our | |
# C++ tests currently link against by default, which would lead to | |
# test failures. To remediate that, we have to tell the C++ tests to | |
# build against the FFmpeg that we installed from conda-forge (which | |
# is able to decode x264). | |
# Note: The Python tests are also decoding x264 files. The Python | |
# tests work fine because even though the library was built against | |
# our pre-built non-GPL at build time, at run time (during test | |
# execution), it's the installed FFmpeg version that is found. | |
# | |
# TODO: We should fix that and | |
# a) build the C++ tests against our pre-built non-GPL FFmpeg, like | |
# for the Python package | |
# b) make sure that the C++ tests can dynamically load the installed | |
# FFmpeg version. | |
# c) ideally, we should avoid re-building the entire libtorchcodec | |
# library just for building the C++ tests. We should be able to | |
# re-use the build that was done when we installed the Python | |
# library and avoid recompilation. | |
build_tests_dir="${PWD}/build_tests" | |
mkdir $build_tests_dir | |
pushd $build_tests_dir | |
TORCH_PATH=$(python -c "import pathlib, torch; print(pathlib.Path(torch.__path__[0]))") | |
Torch_DIR="${TORCH_PATH}/share/cmake/Torch" | |
cmake .. -DTorch_DIR=$Torch_DIR -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DCMAKE_VERBOSE_MAKEFILE=ON | |
cmake --build . | |
ctest | |
popd |