Skip to content

Commit

Permalink
Mac OSS CI use cmake built gtest (pytorch#3713)
Browse files Browse the repository at this point in the history
Summary:
Instead of using buck. Note that for sccache shims, we need to create the tempdir outside of setup-macos.sh, to prevent from files removed after the script finishes.

Pull Request resolved: pytorch#3713

Reviewed By: huydhn

Differential Revision: D57754547

Pulled By: kirklandsign

fbshipit-source-id: b348c6226ca090e38a07c8f58570ab5539a817ce
  • Loading branch information
kirklandsign authored and facebook-github-bot committed May 24, 2024
1 parent 610eb4f commit 5e9db9a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
5 changes: 0 additions & 5 deletions .ci/scripts/setup-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,11 @@ install_sccache() {

export PATH="${SCCACHE_PATH}:${PATH}"

# Create temp directory for sccache shims
TMP_DIR=$(mktemp -d)
trap 'rm -rfv ${TMP_DIR}' EXIT

write_sccache_stub "${TMP_DIR}/c++"
write_sccache_stub "${TMP_DIR}/cc"
write_sccache_stub "${TMP_DIR}/clang++"
write_sccache_stub "${TMP_DIR}/clang"

export PATH="${TMP_DIR}:$PATH"
sccache --zero-stats || true
}

Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/_unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ jobs:
macos:
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
strategy:
matrix:
include:
- build-tool: buck2
with:
runner: macos-m1-stable
python-version: '3.11'
Expand All @@ -53,18 +49,21 @@ jobs:
script: |
set -eux
BUILD_TOOL=${{ matrix.build-tool }}
bash .ci/scripts/setup-conda.sh
# Create temp directory for sccache shims
export TMP_DIR=$(mktemp -d)
export PATH="${TMP_DIR}:$PATH"
trap 'rm -rfv ${TMP_DIR}' EXIT
# Setup MacOS dependencies as there is no Docker support on MacOS atm
PYTHON_EXECUTABLE=python \
EXECUTORCH_BUILD_PYBIND=ON \
CMAKE_ARGS="-DEXECUTORCH_BUILD_COREML=ON -DEXECUTORCH_BUILD_MPS=ON -DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON" \
${CONDA_RUN} --no-capture-output \
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
.ci/scripts/setup-macos.sh cmake
# Run pytest with coverage
${CONDA_RUN} pytest -n auto --cov=./ --cov-report=xml
# Run gtest
${CONDA_RUN} buck2 test runtime/core/... runtime/platform/...
${CONDA_RUN} test/run_oss_cpp_tests.sh
16 changes: 14 additions & 2 deletions test/run_oss_cpp_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@ set -ex
build_executorch() {
cmake . \
-DCMAKE_INSTALL_PREFIX=cmake-out \
-DEXECUTORCH_BUILD_GTESTS=ON \
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
-Bcmake-out
cmake --build cmake-out -j9 --target install
}

build_gtest() {
mkdir -p third-party/googletest/build
pushd third-party/googletest/build
cmake .. -DCMAKE_INSTALL_PREFIX=.
make -j4
make install
popd
}

build_and_run_test() {
local test_dir=$1
cmake "${test_dir}" -Bcmake-out/"${test_dir}" -DCMAKE_INSTALL_PREFIX=cmake-out
cmake "${test_dir}" \
-DCMAKE_INSTALL_PREFIX=cmake-out \
-DCMAKE_PREFIX_PATH="$(pwd)/third-party/googletest/build" \
-Bcmake-out/"${test_dir}"
cmake --build cmake-out/"${test_dir}" -j9

for t in cmake-out/"${test_dir}"/*test; do
Expand Down Expand Up @@ -56,6 +67,7 @@ probe_tests() {
}

build_executorch
build_gtest

if [ -z "$1" ]; then
echo "Running all directories:"
Expand Down

0 comments on commit 5e9db9a

Please sign in to comment.