Skip to content

Commit 85b9f09

Browse files
authored
Static C bridge support (#1008)
1 parent 2cea5c3 commit 85b9f09

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

.github/workflows/per-pr.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,27 @@ jobs:
177177
compose-file: ./docker/docker-compose-ci.yaml
178178
- uses: Swatinem/rust-cache@v2
179179
- run: cargo integ-test docker_
180+
181+
c-bridge-static-link-test:
182+
name: "C bridge static link test"
183+
runs-on: ubuntu-latest
184+
steps:
185+
- uses: actions/checkout@v4
186+
- uses: dtolnay/rust-toolchain@stable
187+
with:
188+
toolchain: 1.88.0
189+
- name: Install protoc
190+
uses: arduino/setup-protoc@v3
191+
with:
192+
# TODO: Upgrade proto once https://github.com/arduino/setup-protoc/issues/99 is fixed
193+
version: "23.x"
194+
repo-token: ${{ secrets.GITHUB_TOKEN }}
195+
196+
- name: Build crate as static library
197+
run: cargo rustc --package temporal-sdk-core-c-bridge --features xz2-static -- --crate-type=staticlib
198+
199+
- name: Build C test program
200+
run: gcc -I./core-c-bridge/include tests/c_bridge_smoke_test.c target/debug/deps/libtemporal_sdk_core_c_bridge.a -lpthread -ldl -lm -o test
201+
202+
- name: Run C test program
203+
run: ./test

core-c-bridge/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ tokio-util = "0.7"
2626
tonic = { workspace = true }
2727
tracing = "0.1"
2828
url = "2.5"
29+
# This is only needed as an explicit dependency so we can enable static as a feature
30+
xz2 = { version = "0.1" }
2931

3032
[dependencies.temporal-client]
3133
path = "../client"
@@ -44,6 +46,8 @@ path = "../sdk-core-protos"
4446
futures-util = "0.3"
4547
thiserror = { workspace = true }
4648

47-
4849
[build-dependencies]
4950
cbindgen = { version = "0.29", default-features = false }
51+
52+
[features]
53+
xz2-static = ["xz2/static"]

core/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ tracing-subscriber = { version = "0.3", default-features = false, features = [
116116
] }
117117
url = "2.5"
118118
uuid = { version = "1.18", features = ["v4"] }
119-
zip = { version = "4.6", optional = true }
119+
# Only need specific features to decompress zip files for ephemeral server download
120+
zip = { version = "4.6", optional = true, default-features = false, features = ["deflate", "bzip2", "zstd"] }
120121

121122
# 1st party local deps
122123
[dependencies.temporal-sdk-core-api]

tests/c_bridge_smoke_test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "temporal-sdk-core-c-bridge.h"
2+
#include <stdio.h>
3+
4+
int main(void) {
5+
// Just do something simple to confirm the bridge works
6+
struct TemporalCoreCancellationToken *tok = temporal_core_cancellation_token_new();
7+
temporal_core_cancellation_token_free(tok);
8+
printf("C bridge smoke test passed!\n");
9+
return 0;
10+
}

0 commit comments

Comments
 (0)