Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/rpm-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
packit rpm-build \
rust cargo gcc gcc-c++ make cmake pkg-config \
clang-devel z3-devel systemd-rpm-macros \
protobuf-compiler protobuf-devel \
pandoc python3-devel git-core \
cargo-rpm-macros

Expand Down
56 changes: 50 additions & 6 deletions crates/openshell-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
proto_files.sort();

// Requires `protoc`. Local and CI builds get it from mise; Docker build
// images install protobuf-compiler. Those protoc distributions also
// provide the well-known type includes used by imports such as
// google/protobuf/struct.proto.
// images and RPM builds install protobuf packages. Some distro protoc
// packages split the well-known type includes into a separate development
// package and do not search that directory automatically, so pass it
// explicitly when it is present.
let mut prost_config = prost_build::Config::new();
if let Some(protoc) = resolve_protoc_from_mise() {
prost_config.protoc_executable(protoc);
}
for include_dir in well_known_proto_include_dirs() {
println!(
"cargo:rerun-if-changed={}",
include_dir.join("google/protobuf/struct.proto").display()
);
prost_config.protoc_arg(format!("--proto_path={}", include_dir.display()));
}
tonic_build::configure()
.build_server(true)
.build_client(true)
Expand All @@ -54,17 +62,53 @@ fn resolve_protoc_from_mise() -> Option<PathBuf> {
return None;
}

let protoc = mise_tool_root("protoc")?.join("bin").join("protoc");
protoc.is_file().then_some(protoc)
}

fn well_known_proto_include_dirs() -> Vec<PathBuf> {
let mut candidates = Vec::new();

if let Some(path) = env::var_os("PROTOC_INCLUDE") {
candidates.push(PathBuf::from(path));
}
if let Some(path) = env::var_os("PROTOC")
&& let Some(root) = Path::new(&path).parent().and_then(Path::parent)
{
candidates.push(root.join("include"));
}
if let Some(root) = mise_tool_root("protoc") {
candidates.push(root.join("include"));
}

candidates.extend([
PathBuf::from("/usr/include"),
PathBuf::from("/usr/local/include"),
PathBuf::from("/opt/homebrew/include"),
]);

let mut dirs = Vec::new();
for candidate in candidates {
if candidate.join("google/protobuf/struct.proto").is_file()
&& !dirs.iter().any(|dir| dir == &candidate)
{
dirs.push(candidate);
}
}
dirs
}

fn mise_tool_root(tool: &str) -> Option<PathBuf> {
let output = std::process::Command::new("mise")
.args(["where", "protoc"])
.args(["where", tool])
.output()
.ok()?;
if !output.status.success() {
return None;
}

let root = String::from_utf8(output.stdout).ok()?;
let protoc = PathBuf::from(root.trim()).join("bin").join("protoc");
protoc.is_file().then_some(protoc)
Some(PathBuf::from(root.trim()))
}

fn command_exists(command: &str) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion deploy/docker/Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ RUN --mount=type=secret,id=MISE_GITHUB_TOKEN \
mise reshim && \
(/root/.cargo/bin/rustup component remove rust-docs || true) && \
rm -rf /root/.rustup/toolchains/*/share/doc /root/.rustup/toolchains/*/share/man && \
helm plugin install https://github.com/helm-unittest/helm-unittest
helm plugin install --verify=false https://github.com/helm-unittest/helm-unittest

# Set working directory for CI jobs
WORKDIR /builds
1 change: 1 addition & 0 deletions deploy/docker/Dockerfile.cli-macos
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
cmake \
curl \
libclang-dev \
libprotobuf-dev \
pkg-config \
protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*
Expand Down
1 change: 1 addition & 0 deletions deploy/docker/Dockerfile.driver-vm-macos
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
clang \
cmake \
curl \
libprotobuf-dev \
pkg-config \
protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*
Expand Down
1 change: 1 addition & 0 deletions deploy/docker/Dockerfile.gateway-macos
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
cmake \
curl \
libclang-dev \
libprotobuf-dev \
pkg-config \
protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*
Expand Down
1 change: 1 addition & 0 deletions deploy/docker/Dockerfile.python-wheels
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libc6-dev \
libclang-dev \
libprotobuf-dev \
pkg-config \
protobuf-compiler \
libssl-dev \
Expand Down
1 change: 1 addition & 0 deletions deploy/docker/Dockerfile.python-wheels-macos
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
libclang-dev \
libssl-dev \
libprotobuf-dev \
pkg-config \
protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*
Expand Down
2 changes: 2 additions & 0 deletions openshell.spec
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ BuildRequires: make
BuildRequires: cmake
BuildRequires: pkg-config
BuildRequires: clang-devel
BuildRequires: protobuf-compiler
BuildRequires: protobuf-devel
BuildRequires: z3-devel
BuildRequires: systemd-rpm-macros

Expand Down
Loading