Skip to content
62 changes: 48 additions & 14 deletions .github/workflows/build-cli-release.reusable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ on:
type: boolean
default: true
required: false

push:
branches:
- protoc-fix
env:
MACOSX_DEPLOYMENT_TARGET: "10.13"

Expand Down Expand Up @@ -69,7 +71,7 @@ jobs:
# shell: bash
# run: |
# ci/ubuntu-install-packages

- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
Expand All @@ -79,8 +81,34 @@ jobs:
with:
go-version: '1.21'

- name: Install protoc-gen-go
run: go install github.com/golang/protobuf/protoc-gen-go@latest
- name: Install protoc-gen-go into .cargo/bin
shell: bash
run: |
# The cross-compile environment sanitizes the PATH, so we install the plugin
# directly into a directory that is guaranteed to be in the PATH for cargo.
# We also create a symlink from the go/bin to the cargo/bin for consistency.
mkdir -p .cargo/bin
go install github.com/golang/protobuf/protoc-gen-go@latest
cp "$HOME/go/bin/protoc-gen-go" ".cargo/bin/"
echo "Installed protoc-gen-go into .cargo/bin:"
ls -la .cargo/bin

- name: Test protoc-gen-go availability
id: protoc_gen_go_setup
shell: bash
run: |
echo "Current PATH: $PATH"
echo "Go bin directory contents:"
ls -la $HOME/go/bin/
echo "Which protoc-gen-go:"
PROTOC_GEN_GO_PATH=$(which protoc-gen-go)
echo "Found protoc-gen-go at: $PROTOC_GEN_GO_PATH"
echo "protoc_gen_go_path=$PROTOC_GEN_GO_PATH" >> $GITHUB_OUTPUT
echo "Testing protoc can find protoc-gen-go plugin..."
# Test that protoc can find the go plugin (this will show an error about missing .proto file, but that's expected)
protoc --go_out=/tmp --help | grep -q "go_out" && echo "✅ protoc recognizes --go_out flag" || echo "❌ protoc does not recognize --go_out flag"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider failing the step if '--go_out' isn’t recognized instead of only echoing a message.

Suggested change
protoc --go_out=/tmp --help | grep -q "go_out" && echo "✅ protoc recognizes --go_out flag" || echo "❌ protoc does not recognize --go_out flag"
protoc --go_out=/tmp --help | grep -q "go_out" && echo "✅ protoc recognizes --go_out flag" || (echo "❌ protoc does not recognize --go_out flag"; exit 1)




- name: Use Cross
if: contains(matrix._.os, 'ubuntu')
Expand Down Expand Up @@ -111,18 +139,24 @@ jobs:
workspaces: engine
prefix-key: "v5-rust-${{ matrix._.target }}"

# Build the CLI - Always use static-ssl features
- name: Build CLI Binary
# This single step now handles all builds
run: >
${{ env.CARGO }} build --release --bin baml-cli ${{ env.TARGET_FLAGS }}
--features static-ssl
--no-default-features
working-directory: engine
# # Build the CLI - Always use static-ssl features
# - name: Build CLI Binary
# # This single step now handles all builds
# run: >
# ${{ env.CARGO }} build --release --bin baml-cli ${{ env.TARGET_FLAGS }}
# --features static-ssl
# --no-default-features
# working-directory: engine

- name: Build CFFI Library
run: >
${{ env.CARGO }} build --release -p baml_cffi ${{ env.TARGET_FLAGS }}
shell: bash
env:
PROTOC_GEN_GO_PATH: ${{ steps.protoc_gen_go_setup.outputs.protoc_gen_go_path }}
run: |
echo "Using PROTOC_GEN_GO_PATH: $PROTOC_GEN_GO_PATH"
# We must use PROTOC_GEN_GO_PATH to explicitly tell the build script
# where to find the plugin, as the cross-compile environment is isolated.
${{ env.CARGO }} build -p baml_cffi ${{ env.TARGET_FLAGS }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the invalid '--debug' flag. Note: Cargo defaults to a debug build, but later steps reference artifacts in the release directory. Confirm if a release build (i.e., using --release) is intended for consistency.

Suggested change
${{ env.CARGO }} build -p baml_cffi ${{ env.TARGET_FLAGS }}
${{ env.CARGO }} build --release -p baml_cffi ${{ env.TARGET_FLAGS }}

working-directory: engine
# Skip this step on Windows runners
if: matrix._.os != 'windows-2022'
Expand Down
19 changes: 17 additions & 2 deletions engine/language_client_cffi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ mod protoc_lang_out {
}

fn main() -> std::io::Result<()> {
#[cfg(target_os = "windows")]
println!("cargo:rustc-link-lib=dylib=ntdll");

// The last component of the target triple
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let is_windows = target_os == "windows";

// Re-run build.rs if these files change.
println!("cargo:rerun-if-changed=types/cffi.fbs");
println!("cargo:rerun-if-changed=types/cffi.proto");
Expand All @@ -348,10 +355,18 @@ fn main() -> std::io::Result<()> {
// ..Default::default()
// };

protoc_lang_out::ProtocLangOut::new()
let mut protoc = protoc_lang_out::ProtocLangOut::new();
protoc
.lang(lang)
.input("types/cffi.proto")
.out_dir(lang_dir)
.out_dir(lang_dir);

// Allow overriding the protoc-gen-go plugin path
if let Ok(path) = std::env::var("PROTOC_GEN_GO_PATH") {
protoc.plugin(&path);
}

protoc
.run()
.unwrap_or_else(|_| panic!("Failed to generate {lang} bindings"));
}
Expand Down
Loading