From 7955e3778596a15288d92d01499a1a6e880e6beb Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 22 Jan 2025 10:19:28 -0800 Subject: [PATCH] Add some FFI tests --- .github/workflows/rust.yml | 23 +++++++++++++++++++++++ temporal_capi/.gitignore | 3 +++ temporal_capi/cpp_tests/Makefile | 25 +++++++++++++++++++++++++ temporal_capi/cpp_tests/simple.cpp | 17 +++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 temporal_capi/.gitignore create mode 100644 temporal_capi/cpp_tests/Makefile create mode 100644 temporal_capi/cpp_tests/simple.cpp diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d924868bb..be32444b8 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -85,6 +85,29 @@ jobs: run: cargo build --quiet --all-features - name: Test --all-features run: cargo test --all-features + ffi: + name: Test FFI (${{ matrix.rust.name }}, ${{ matrix.os }}) + strategy: + matrix: + rust: + - { version: stable, name: stable } + os: [ubuntu-latest] # Todo: potentially add more if we add cpp tests + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust.version }} + - uses: Swatinem/rust-cache@v2 + with: + key: ffi + - name: Cargo build + run: cargo build -p temporal_capi + - name: Regen + run: cargo run -p diplomat-gen + # Todo: eventually we should check in bindings and test them + - name: Makefile tests + run: cd temporal_capi/cpp_tests && make docs: name: Documentation diff --git a/temporal_capi/.gitignore b/temporal_capi/.gitignore new file mode 100644 index 000000000..132bfa416 --- /dev/null +++ b/temporal_capi/.gitignore @@ -0,0 +1,3 @@ +# To be checked in later once it stabilizes a bit +bindings/ +*.out \ No newline at end of file diff --git a/temporal_capi/cpp_tests/Makefile b/temporal_capi/cpp_tests/Makefile new file mode 100644 index 000000000..abaed3e02 --- /dev/null +++ b/temporal_capi/cpp_tests/Makefile @@ -0,0 +1,25 @@ +.DEFAULT_GOAL := test +.PHONY: build test +FORCE: + +HEADERS := ../bindings/cpp/ +ALL_HEADERS := $(wildcard ${HEADERS}/**/*.hpp) + +CXX?=g++ + +TEST_FILES := $(wildcard *.cpp) +OUT_FILES = $(patsubst %.cpp,%.out,$(TEST_FILES)) + +$(ALL_HEADERS): + +../../target/debug/libtemporal_capi.a: FORCE + cargo rustc -p temporal_capi --crate-type staticlib + +%.out: %.cpp ../../target/debug/libtemporal_capi.a $(ALL_HEADERS) + $(CXX) -std=c++17 -L ../../target/debug/ -I ${HEADERS} $< -ltemporal_capi -lm -o $@ + ./$@ + +test: $(OUT_FILES) + +clean: + rm $(OUT_FILES) diff --git a/temporal_capi/cpp_tests/simple.cpp b/temporal_capi/cpp_tests/simple.cpp new file mode 100644 index 000000000..35b1a3b4c --- /dev/null +++ b/temporal_capi/cpp_tests/simple.cpp @@ -0,0 +1,17 @@ +#include +#include + +#include + +using namespace temporal_rs; + +int main() { + auto c = Calendar::create(AnyCalendarKind::Gregorian); + + auto date = PlainDate::create_with_overflow(2025, 1, 33, *c, ArithmeticOverflow::Constrain).ok().value(); + + auto formatted = date->to_ixdtf_string(DisplayCalendar::Always); + + std::cout<