Skip to content

Commit

Permalink
Include the native client in the pantsbuild wheel.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuhood committed Apr 25, 2023
1 parent a39c1b9 commit 9707db3
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 19 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test-cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
uses: actions/cache@v3
with:
key: Linux-ARM64-engine-${{ steps.get-engine-hash.outputs.hash }}-v1
path: '.pants
path: 'src/python/pants/bin/native_client
src/python/pants/engine/internals/native_engine.so
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: native_binaries.${{ matrix.python-version }}.Linux-ARM64
path: '.pants
path: 'src/python/pants/bin/native_client
src/python/pants/engine/internals/native_engine.so
Expand Down Expand Up @@ -155,7 +155,7 @@ jobs:
uses: actions/cache@v3
with:
key: Linux-x86_64-engine-${{ steps.get-engine-hash.outputs.hash }}-v1
path: '.pants
path: 'src/python/pants/bin/native_client
src/python/pants/engine/internals/native_engine.so
Expand Down Expand Up @@ -191,7 +191,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: native_binaries.${{ matrix.python-version }}.Linux-x86_64
path: '.pants
path: 'src/python/pants/bin/native_client
src/python/pants/engine/internals/native_engine.so
Expand Down Expand Up @@ -268,7 +268,7 @@ jobs:
uses: actions/cache@v3
with:
key: macOS11-x86_64-engine-${{ steps.get-engine-hash.outputs.hash }}-v1
path: '.pants
path: 'src/python/pants/bin/native_client
src/python/pants/engine/internals/native_engine.so
Expand Down Expand Up @@ -304,7 +304,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: native_binaries.${{ matrix.python-version }}.macOS11-x86_64
path: '.pants
path: 'src/python/pants/bin/native_client
src/python/pants/engine/internals/native_engine.so
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
uses: actions/cache@v3
with:
key: Linux-ARM64-engine-${{ steps.get-engine-hash.outputs.hash }}-v1
path: '.pants
path: 'src/python/pants/bin/native_client
src/python/pants/engine/internals/native_engine.so
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: native_binaries.${{ matrix.python-version }}.Linux-ARM64
path: '.pants
path: 'src/python/pants/bin/native_client
src/python/pants/engine/internals/native_engine.so
Expand Down Expand Up @@ -158,7 +158,7 @@ jobs:
uses: actions/cache@v3
with:
key: Linux-x86_64-engine-${{ steps.get-engine-hash.outputs.hash }}-v1
path: '.pants
path: 'src/python/pants/bin/native_client
src/python/pants/engine/internals/native_engine.so
Expand Down Expand Up @@ -193,7 +193,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: native_binaries.${{ matrix.python-version }}.Linux-x86_64
path: '.pants
path: 'src/python/pants/bin/native_client
src/python/pants/engine/internals/native_engine.so
Expand Down Expand Up @@ -270,7 +270,7 @@ jobs:
uses: actions/cache@v3
with:
key: macOS11-x86_64-engine-${{ steps.get-engine-hash.outputs.hash }}-v1
path: '.pants
path: 'src/python/pants/bin/native_client
src/python/pants/engine/internals/native_engine.so
Expand Down Expand Up @@ -305,7 +305,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: native_binaries.${{ matrix.python-version }}.macOS11-x86_64
path: '.pants
path: 'src/python/pants/bin/native_client
src/python/pants/engine/internals/native_engine.so
Expand Down
2 changes: 1 addition & 1 deletion build-support/bin/generate_github_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def hashFiles(path: str) -> str:


NATIVE_FILES = [
".pants",
"src/python/pants/bin/native_client",
"src/python/pants/engine/internals/native_engine.so",
"src/python/pants/engine/internals/native_engine.so.metadata",
]
Expand Down
8 changes: 4 additions & 4 deletions build-support/bin/rust/bootstrap_code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ case "${KERNEL}" in
esac

readonly NATIVE_ENGINE_BINARY="native_engine.so"
export NATIVE_CLIENT_BINARY="${REPO_ROOT}/src/python/pants/bin/native_client"
readonly NATIVE_ENGINE_RESOURCE="${REPO_ROOT}/src/python/pants/engine/internals/${NATIVE_ENGINE_BINARY}"
readonly NATIVE_ENGINE_RESOURCE_METADATA="${NATIVE_ENGINE_RESOURCE}.metadata"
readonly NATIVE_CLIENT_PATH="${REPO_ROOT}/.pants"
readonly NATIVE_CLIENT_TARGET="${NATIVE_ROOT}/target/${MODE}/pants"

function _build_native_code() {
Expand All @@ -55,7 +55,7 @@ function bootstrap_native_code() {
engine_version_in_metadata="$(sed -n 's/^engine_version: //p' "${NATIVE_ENGINE_RESOURCE_METADATA}")"
fi

if [[ -f "${NATIVE_ENGINE_RESOURCE}" && -f "${NATIVE_CLIENT_PATH}" &&
if [[ -f "${NATIVE_ENGINE_RESOURCE}" && -f "${NATIVE_CLIENT_BINARY}" &&
"${engine_version_calculated}" == "${engine_version_in_metadata}" ]]; then
return 0
fi
Expand All @@ -79,9 +79,9 @@ function bootstrap_native_code() {
# Create the native engine resource.
# NB: On Mac Silicon, for some reason, first removing the old native_engine.so is necessary to avoid the Pants
# process from being killed when recompiling.
rm -f "${NATIVE_ENGINE_RESOURCE}" "${NATIVE_CLIENT_PATH}"
rm -f "${NATIVE_ENGINE_RESOURCE}" "${NATIVE_CLIENT_BINARY}"
cp "${native_binary}" "${NATIVE_ENGINE_RESOURCE}"
cp "${NATIVE_CLIENT_TARGET}" "${NATIVE_CLIENT_PATH}"
cp "${NATIVE_CLIENT_TARGET}" "${NATIVE_CLIENT_BINARY}"

# Create the accompanying metadata file.
local -r metadata_file=$(mktemp -t pants.native_engine.metadata.XXXXXX)
Expand Down
3 changes: 1 addition & 2 deletions pants
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ source "${HERE}/build-support/pants_venv"
source "${HERE}/build-support/bin/rust/bootstrap_code.sh"

function exec_pants_bare() {
PANTS_NATIVE_EXE="${HERE}/.pants"
PANTS_PY_EXE="${HERE}/src/python/pants/bin/pants_loader.py"
PANTS_SRCPATH="${HERE}/src/python"

Expand All @@ -51,7 +50,7 @@ function exec_pants_bare() {

if [ -n "${USE_NATIVE_PANTS}" ]; then
set +e
"${PANTS_NATIVE_EXE}" "$@"
"${NATIVE_CLIENT_BINARY}" "$@"
result=$?
# N.B.: The native pants client currently relies on pantsd being up. If it's not, it will fail
# with exit code 75 (EX_TEMPFAIL in /usr/include/sysexits.h) and we should fall through to the
Expand Down
2 changes: 2 additions & 0 deletions src/python/pants/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ python_distribution(
dependencies=[
"./__main__.py",
":resources",
# Include the native client binary in the distribution.
"src/python/pants/bin:native_client",
],
# Because we have native code, this will cause the wheel to use whatever the ABI is for the
# interpreter used to run setup.py, e.g. `cp36m-macosx_10_15_x86_64`.
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/native_client
4 changes: 4 additions & 0 deletions src/python/pants/bin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,9 @@ pex_binary(
strip_pex_env=False,
)

resources(
name="native_client",
sources=["native_client"],
)

python_tests(name="tests")

0 comments on commit 9707db3

Please sign in to comment.