Skip to content

Commit

Permalink
Get rid of engine_cffi crate, and inline into the engine crate.
Browse files Browse the repository at this point in the history
[ci skip-jvm-tests]
  • Loading branch information
stuhood committed May 17, 2020
1 parent 95ab23b commit 0f49f4f
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 64 deletions.
7 changes: 4 additions & 3 deletions build-support/bin/native/bootstrap_code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ function _build_native_code() {
# Change into $REPO_ROOT in a subshell. This is necessary so that we're in a child of a
# directory containing the rust-toolchain file, so that rustup knows which version of rust we
# should be using.
# NB: See Cargo.toml with regard to the `extension-module` feature.
cd "${REPO_ROOT}"
"${REPO_ROOT}/build-support/bin/native/cargo" build ${MODE_FLAG} \
--manifest-path "${NATIVE_ROOT}/Cargo.toml" -p engine_cffi
"${REPO_ROOT}/build-support/bin/native/cargo" build --features=extension-module ${MODE_FLAG} \
--manifest-path "${NATIVE_ROOT}/Cargo.toml" -p engine
) || die
echo "${NATIVE_ROOT}/target/${MODE}/libengine_cffi.${LIB_EXTENSION}"
echo "${NATIVE_ROOT}/target/${MODE}/libengine.${LIB_EXTENSION}"
}

function bootstrap_native_code() {
Expand Down
11 changes: 11 additions & 0 deletions build-support/bin/native/cargo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set -e
REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd ../../.. && pwd -P)

export PY=${PY:-python3}
# Consumed by the cpython crate.
export PYTHON_SYS_EXECUTABLE="${PY}"

# Exports:
# + CARGO_HOME: The CARGO_HOME of the Pants-controlled rust toolchain.
Expand All @@ -15,8 +17,17 @@ export PY=${PY:-python3}
# shellcheck source=build-support/bin/native/bootstrap_rust.sh
source "${REPO_ROOT}/build-support/bin/native/bootstrap_rust.sh"

# Exposes:
# + activate_pants_venv: Activate a virtualenv for pants requirements, creating it if needed.
#
# This is necessary for any `cpython`-dependent crates, which need a python interpeter on the PATH.
# shellcheck source=build-support/pants_venv
source "${REPO_ROOT}/build-support/pants_venv"

bootstrap_rust >&2

activate_pants_venv

download_binary="${REPO_ROOT}/build-support/bin/download_binary.sh"

# The following is needed by grpcio-sys and we have no better way to hook its build.rs than this;
Expand Down
7 changes: 7 additions & 0 deletions build-support/pants_venv
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ MESSAGE
}

function activate_pants_venv() {
# Allow for multiple calls to `activate_pants_venv`.
if [ -n "$VENV_ACTIVATED_FOR_PANTS" ]; then
return
else
export VENV_ACTIVATED_FOR_PANTS="true"
fi

fingerprint=""
for req in "${REQUIREMENTS[@]}"; do
fingerprint="${fingerprint}$(fingerprint_data < "${req}")"
Expand Down
2 changes: 0 additions & 2 deletions src/rust/engine/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
/*/**/Cargo.lock
!fs/fs_util/Cargo.lock
!process_executor/Cargo.lock
engine_cffi/logs/
engine_cffi/src/cffi/
# These modules contain purely generated code.
process_execution/bazel_protos/src/gen/
process_execution/bazel_protos/src/gen_for_tower/
22 changes: 1 addition & 21 deletions src/rust/engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions src/rust/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ members = [
"async_semaphore",
"boxfuture",
"concrete_time",
"engine_cffi",
"fs",
"fs/brfs",
"fs/fs_util",
Expand Down Expand Up @@ -60,7 +59,6 @@ default-members = [
"async_semaphore",
"boxfuture",
"concrete_time",
"engine_cffi",
"fs",
"fs/fs_util",
"fs/store",
Expand All @@ -84,6 +82,18 @@ default-members = [
"workunit_store"
]

[lib]
crate-type = ["cdylib"]

[features]
# NB: To actually load this crate from python, the `extension-module` feature must be enabled. But
# unfortunately, enabling `extension-module` causes tests linked against `cpython` to fail. We
# define a feature to enable that, but we do not enable it by default: someone building this module
# in order to extract `libengine.so` should pass `cargo build .. --features=extension-module`.
# see https://github.com/PyO3/pyo3/issues/340
extension-module = ["cpython/extension-module"]
default = []

[dependencies]
async_semaphore = { path = "async_semaphore" }
async-trait = "0.1"
Expand Down Expand Up @@ -114,6 +124,7 @@ rule_graph = { path = "rule_graph" }
sharded_lmdb = { path = "sharded_lmdb" }
smallvec = "0.6"
store = { path = "fs/store" }
tar_api = { path = "tar_api" }
task_executor = { path = "task_executor" }
tempfile = "3"
time = "0.1.40"
Expand Down
File renamed without changes.
26 changes: 0 additions & 26 deletions src/rust/engine/engine_cffi/Cargo.toml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
clippy::transmute_ptr_to_ptr,
clippy::zero_ptr
)]
// There are some large async-await types generated here. Nothing to worry about?
#![type_length_limit = "2066838"]

///
/// This crate is a wrapper around the engine crate which exposes a python module via cpython.
Expand All @@ -45,7 +43,7 @@ use cpython::{
PyResult as CPyResult, PyTuple, PyType, Python, PythonObject,
};

use engine::{
use crate::{
externs, nodes, Core, ExecutionRequest, ExecutionTermination, Failure, Function, Intrinsics,
Params, Rule, Scheduler, Session, Tasks, Types, Value,
};
Expand All @@ -71,9 +69,6 @@ use tempfile::TempDir;
use tokio;
use workunit_store::{Workunit, WorkunitState};

#[cfg(test)]
mod tests;

py_exception!(native_engine, PollTimeout);

py_module_initializer!(native_engine, |py, m| {
Expand Down Expand Up @@ -1112,7 +1107,7 @@ fn rule_subgraph_visualize(
})
}

fn generate_panic_string(payload: &(dyn Any + Send)) -> String {
pub(crate) fn generate_panic_string(payload: &(dyn Any + Send)) -> String {
match payload
.downcast_ref::<String>()
.cloned()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::generate_panic_string;
use crate::externs::interface::generate_panic_string;

use std::any::Any;

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
clippy::zero_ptr
)]

mod interface;
#[cfg(test)]
mod interface_tests;

use std::collections::BTreeMap;
use std::fmt;
use std::sync::atomic;
Expand Down
4 changes: 2 additions & 2 deletions src/rust/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@

mod context;
mod core;
pub mod externs;
mod externs;
mod interning;
mod intrinsics;
pub mod nodes;
mod nodes;
mod scheduler;
mod selectors;
mod tasks;
Expand Down

0 comments on commit 0f49f4f

Please sign in to comment.