Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some FFI tests #179

Merged
merged 2 commits into from
Jan 25, 2025
Merged
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
23 changes: 23 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions temporal_capi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# To be checked in later once it stabilizes a bit
bindings/
*.out
25 changes: 25 additions & 0 deletions temporal_capi/cpp_tests/Makefile
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions temporal_capi/cpp_tests/simple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <temporal_rs/Calendar.hpp>
#include <temporal_rs/PlainDate.hpp>

#include <iostream>

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<<formatted<<std::endl;

}
Loading