Skip to content

Commit

Permalink
Revert "Start incremental migration from rust-cpython to PyO3 (pantsb…
Browse files Browse the repository at this point in the history
…uild#12110)"

This reverts commit 7a36876.
  • Loading branch information
Eric-Arellano committed Jun 9, 2021
1 parent b971c85 commit 5745753
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 398 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/test-cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ jobs:
'
path: 'src/python/pants/engine/internals/native_engine.so
src/python/pants/engine/internals/native_engine_pyo3.so
src/python/pants/engine/internals/native_engine.so.metadata'
- name: Bootstrap Pants
run: './pants --version
Expand Down Expand Up @@ -133,8 +131,6 @@ jobs:
name: native_engine.so.${{ matrix.python-version }}.${{ runner.os }}
path: 'src/python/pants/engine/internals/native_engine.so
src/python/pants/engine/internals/native_engine_pyo3.so
src/python/pants/engine/internals/native_engine.so.metadata'
- if: '!contains(env.COMMIT_MESSAGE, ''[ci skip-rust]'')'
name: Test and Lint Rust
Expand Down Expand Up @@ -246,8 +242,6 @@ jobs:
'
path: 'src/python/pants/engine/internals/native_engine.so
src/python/pants/engine/internals/native_engine_pyo3.so
src/python/pants/engine/internals/native_engine.so.metadata'
- name: Bootstrap Pants
run: './pants --version
Expand All @@ -259,8 +253,6 @@ jobs:
name: native_engine.so.${{ matrix.python-version }}.${{ runner.os }}
path: 'src/python/pants/engine/internals/native_engine.so
src/python/pants/engine/internals/native_engine_pyo3.so
src/python/pants/engine/internals/native_engine.so.metadata'
- env:
TMPDIR: ${{ runner.temp }}
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ jobs:
'
path: 'src/python/pants/engine/internals/native_engine.so
src/python/pants/engine/internals/native_engine_pyo3.so
src/python/pants/engine/internals/native_engine.so.metadata'
- name: Bootstrap Pants
run: './pants --version
Expand Down Expand Up @@ -133,8 +131,6 @@ jobs:
name: native_engine.so.${{ matrix.python-version }}.${{ runner.os }}
path: 'src/python/pants/engine/internals/native_engine.so
src/python/pants/engine/internals/native_engine_pyo3.so
src/python/pants/engine/internals/native_engine.so.metadata'
- if: '!contains(env.COMMIT_MESSAGE, ''[ci skip-rust]'')'
name: Test and Lint Rust
Expand Down Expand Up @@ -245,8 +241,6 @@ jobs:
'
path: 'src/python/pants/engine/internals/native_engine.so
src/python/pants/engine/internals/native_engine_pyo3.so
src/python/pants/engine/internals/native_engine.so.metadata'
- name: Bootstrap Pants
run: './pants --version
Expand All @@ -258,8 +252,6 @@ jobs:
name: native_engine.so.${{ matrix.python-version }}.${{ runner.os }}
path: 'src/python/pants/engine/internals/native_engine.so
src/python/pants/engine/internals/native_engine_pyo3.so
src/python/pants/engine/internals/native_engine.so.metadata'
- env:
TMPDIR: ${{ runner.temp }}
Expand Down
1 change: 0 additions & 1 deletion build-support/bin/generate_github_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

NATIVE_ENGINE_SO_FILES = [
"src/python/pants/engine/internals/native_engine.so",
"src/python/pants/engine/internals/native_engine_pyo3.so",
"src/python/pants/engine/internals/native_engine.so.metadata",
]

Expand Down
36 changes: 9 additions & 27 deletions build-support/bin/rust/bootstrap_code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd ../../.. && pwd -P)"

# shellcheck source=build-support/common.sh
source "${REPO_ROOT}/build-support/common.sh"

# Defines:
# + NATIVE_ROOT: The Rust code directory, ie: src/rust/engine.
# + MODE: Whether to run in debug or release mode.
Expand All @@ -31,9 +28,7 @@ case "${KERNEL}" in
esac

readonly NATIVE_ENGINE_BINARY="native_engine.so"
readonly NATIVE_ENGINE_BINARY_PYO3="native_engine_pyo3.so"
readonly NATIVE_ENGINE_RESOURCE="${REPO_ROOT}/src/python/pants/engine/internals/${NATIVE_ENGINE_BINARY}"
readonly NATIVE_ENGINE_RESOURCE_PYO3="${REPO_ROOT}/src/python/pants/engine/internals/${NATIVE_ENGINE_BINARY_PYO3}"
readonly NATIVE_ENGINE_RESOURCE_METADATA="${NATIVE_ENGINE_RESOURCE}.metadata"

function _build_native_code() {
Expand All @@ -42,21 +37,15 @@ function _build_native_code() {
echo "${NATIVE_ROOT}/target/${MODE}/libengine.${LIB_EXTENSION}"
}

function _build_native_code_pyo3() {
# NB: See engine_pyo3/Cargo.toml with regard to the `extension-module` feature.
"${REPO_ROOT}/cargo" build --features=engine_pyo3/extension-module ${MODE_FLAG} -p engine_pyo3 || die
echo "${NATIVE_ROOT}/target/${MODE}/libengine_pyo3.${LIB_EXTENSION}"
}

function bootstrap_native_code() {
# We expose a safety valve to skip compilation iff the user already has `native_engine.so`. This
# can result in using a stale `native_engine.so`, but we trust that the user knows what
# they're doing.
if [[ "${SKIP_NATIVE_ENGINE_SO_BOOTSTRAP}" == "true" ]]; then
if [[ ! -f "${NATIVE_ENGINE_RESOURCE}" || ! -f "${NATIVE_ENGINE_RESOURCE_PYO3}" ]]; then
die "You requested to override bootstrapping native_engine.so and native_engine_pyo3.so via the env var" \
"SKIP_NATIVE_ENGINE_SO_BOOTSTRAP, but the files do not exist at" \
"${NATIVE_ENGINE_RESOURCE} and ${NATIVE_ENGINE_BINARY_PYO3}. This is not safe to do."
if [[ ! -f "${NATIVE_ENGINE_RESOURCE}" ]]; then
die "You requested to override bootstrapping native_engine.so via the env var" \
"SKIP_NATIVE_ENGINE_SO_BOOTSTRAP, but the file does not exist at" \
"${NATIVE_ENGINE_RESOURCE}. This is not safe to do."
fi
return
fi
Expand All @@ -67,20 +56,14 @@ function bootstrap_native_code() {
if [[ -f "${NATIVE_ENGINE_RESOURCE_METADATA}" ]]; then
engine_version_in_metadata="$(sed -n 's/^engine_version: //p' "${NATIVE_ENGINE_RESOURCE_METADATA}")"
fi
if [[ ! -f "${NATIVE_ENGINE_RESOURCE}" || ! -f "${NATIVE_ENGINE_RESOURCE_PYO3}" || "${engine_version_calculated}" != "${engine_version_in_metadata}" ]]; then
banner "Building native engine..."
banner "Building native_engine.so"
local -r native_binary="$(_build_native_code)" || die
banner "Building native_engine_pyo3.so"
local -r native_binary_pyo3="$(_build_native_code_pyo3)" || die
if [[ ! -f "${NATIVE_ENGINE_RESOURCE}" || "${engine_version_calculated}" != "${engine_version_in_metadata}" ]]; then
echo "Building native engine"
local -r native_binary="$(_build_native_code)"

# If bootstrapping the native engine fails, don't attempt to run pants
# afterwards.
if [[ ! -f "${native_binary}" ]]; then
die "Failed to build native engine, file missing at ${native_binary}."
fi
if [[ ! -f "${native_binary_pyo3}" ]]; then
die "Failed to build native engine, file missing at ${native_binary_pyo3}."
die "Failed to build native engine."
fi

# Pick up Cargo.lock changes if any caused by the `cargo build`.
Expand All @@ -89,9 +72,8 @@ 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_ENGINE_RESOURCE_PYO3}"
rm -f "${NATIVE_ENGINE_RESOURCE}"
cp "${native_binary}" "${NATIVE_ENGINE_RESOURCE}"
cp "${native_binary_pyo3}" "${NATIVE_ENGINE_RESOURCE_PYO3}"

# Create the accompanying metadata file.
local -r metadata_file=$(mktemp -t pants.native_engine.metadata.XXXXXX)
Expand Down
1 change: 0 additions & 1 deletion cargo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ source "${REPO_ROOT}/build-support/common.sh"

PY="$(determine_python)"
export PY
export PYO3_PYTHON="${PY}"
export PYTHON_SYS_EXECUTABLE="${PY}" # Consumed by the cpython crate.

if ! command -v rustup &> /dev/null; then
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/engine/internals/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/native_engine.so
/native_engine_pyo3.so
/native_engine.so.metadata
4 changes: 2 additions & 2 deletions src/python/pants/engine/internals/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ python_tests(

python_library(
name='native',
sources=['native_engine.pyi', 'native_engine_pyo3.pyi'],
sources=['native_engine.pyi'],
dependencies=[':native_engine'],
)

resources(
name='native_engine',
sources=['native_engine.so', 'native_engine_pyo3.so', 'native_engine.so.metadata'],
sources=['native_engine.so', 'native_engine.so.metadata'],
)

resources(
Expand Down
9 changes: 9 additions & 0 deletions src/python/pants/engine/internals/native_engine.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ class PyTasks:
class PyTypes:
def __init__(self, **kwargs: Any) -> None: ...

class PyStubCASBuilder:
def always_errors(self) -> None: ...
def build(self, executor: PyExecutor) -> PyStubCAS: ...

class PyStubCAS:
@classmethod
def builder(cls) -> PyStubCASBuilder: ...
def address(self) -> str: ...

class PyStdioDestination:
pass

Expand Down
19 changes: 0 additions & 19 deletions src/python/pants/engine/internals/native_engine_pyo3.pyi

This file was deleted.

Loading

0 comments on commit 5745753

Please sign in to comment.