Skip to content

Commit f9ca424

Browse files
committed
Split external-proto into two features
- `generate-proto`: when enabled, proto.rs is generated at build time. When it is disabled, it is presumed that proto.rs has already been generated - `protobuf-src`: when enabled, protoc is built from source using a build-dependency on protobuf-src. When it is disabled, `PROTOC` must be set by the builder in the environment to a protobuf compiler Signed-off-by: Tom Jakubowski <tom@prospective.dev>
1 parent f8a5798 commit f9ca424

File tree

7 files changed

+35
-13
lines changed

7 files changed

+35
-13
lines changed

rust/generate-metadata/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ path = "../perspective-server"
3030
features = ["external-cpp", "disable-cpp"]
3131

3232
[dependencies.perspective-client]
33+
features = ["generate-proto", "omit_metadata", "protobuf-src"]
3334
path = "../perspective-client"
34-
features = ["external-proto", "omit_metadata"]
3535

3636
[dependencies.perspective-js]
3737
path = "../perspective-js"

rust/perspective-client/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ default = []
3838

3939
# Should the project build the `proto.rs` via protoc from source or assume it
4040
# already exists?
41-
external-proto = ["protobuf-src"]
41+
generate-proto = []
42+
# Should the project build protobuf from source? If not, building this crate
43+
# requires PROTOC be set in the environment
44+
protobuf-src = ["dep:protobuf-src"]
4245

4346
# When generating metadata, we can't rely on its existence - so enable this
4447
# to skip metadata generation. This currently only affects docs.

rust/perspective-client/build.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn prost_build() -> Result<()> {
2424
// This source file is included at `publish` time, but not `sbuild` time
2525
// because it is initially generated from the `perspective.proto` definition
2626
// in the C++ source.
27-
if std::env::var("CARGO_FEATURE_EXTERNAL_PROTO").is_ok() {
27+
if std::env::var("CARGO_FEATURE_GENERATE_PROTO").is_ok() {
2828
println!("cargo:warning=MESSAGE Building in development mode");
2929
let root_dir_env = std::env::var("PSP_ROOT_DIR").expect("Must set PSP_ROOT_DIR");
3030
let root_dir = Path::new(root_dir_env.as_str());
@@ -36,8 +36,19 @@ fn prost_build() -> Result<()> {
3636

3737
println!("cargo:rerun-if-changed={}", proto_file.to_str().unwrap());
3838

39-
#[cfg(feature = "external-proto")]
39+
// prost_build reads PROTOC from the environment. When the `protobuf-src`
40+
// feature is enabled, the build script sets PROTOC to the one built by
41+
// that crate. When protobuf-src is disabled, builders must set PROTOC
42+
// in the environment to a protocol buffer compiler.
43+
#[cfg(feature = "protobuf-src")]
4044
std::env::set_var("PROTOC", protobuf_src::protoc());
45+
#[cfg(not(feature = "protobuf-src"))]
46+
if std::env::var("PROTOC").is_err() {
47+
panic!(
48+
"generate-proto is enabled and protobuf-src is disabled. PROTOC must be set in \
49+
the environment to the path of a protocol buffer compiler"
50+
)
51+
}
4152

4253
prost_build::Config::new()
4354
// .bytes(["ViewToArrowResp.arrow", "from_arrow"])

rust/perspective-js/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ path = "src/rust/lib.rs"
3434
export-init = []
3535
metadata = []
3636
default = []
37-
external-cpp = ["perspective-client/external-proto"]
37+
external-cpp = [
38+
"perspective-client/generate-proto",
39+
"perspective-client/protobuf-src",
40+
]
3841

3942
[build-dependencies]
4043
serde_json = { version = "1.0.107", features = ["raw_value"] }

rust/perspective-python/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ rustdoc-args = ["--html-in-header", "docs/index.html"]
3737

3838
[features]
3939
default = []
40-
external-cpp = [
41-
"perspective-client/external-proto",
42-
"perspective-server/external-cpp",
43-
]
4440
abi3 = ["pyo3/abi3-py39"]
41+
external-cpp = ["perspective-server/external-cpp"]
42+
generate-proto = ["perspective-client/generate-proto"]
43+
protobuf-src = ["perspective-client/protobuf-src"]
4544

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

rust/perspective-python/build.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ if (build_wheel) {
8989
}
9090

9191
if (process.env.CONDA_BUILD === "1") {
92-
console.log("Building with Conda flags for maturin");
92+
console.log("Building with Conda flags and features");
9393
if (process.env.PYTHON) {
9494
console.log(`interpreter: ${process.env.PYTHON}`);
9595
flags += ` --interpreter=${process.env.PYTHON}`;
@@ -98,9 +98,14 @@ if (build_wheel) {
9898
"Expected PYTHON to be set in CONDA_BUILD environment, but it isn't. maturin will likely detect the wrong Python."
9999
);
100100
}
101+
// we need to generate proto.rs using conda's protoc, which is set in
102+
// the environment. we use the unstable "versioned" python abi
103+
features.push(["generate-proto"]);
101104
} else {
102-
console.log("Building with regular flags for maturin");
103-
features.push("abi3");
105+
// standard for in-repo builds. a different set will be standard in the sdist
106+
const standard_features = ["abi3", "generate-proto", "protobuf-src"];
107+
console.log("Building with standard flags and features");
108+
features.push(...standard_features);
104109
}
105110

106111
cmd.sh(`maturin build ${flags} --features=${features.join(",")} ${target}`);

rust/perspective/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ default = ["axum-ws"]
3232
axum-ws = ["tokio", "axum", "futures"]
3333
external-cpp = [
3434
"perspective-server/external-cpp",
35-
"perspective-client/external-proto",
35+
"perspective-client/generate-proto",
36+
"perspective-client/protobuf-src",
3637
]
3738

3839
[dependencies]

0 commit comments

Comments
 (0)