improve c library

This commit is contained in:
Vinzenz Schroeter 2024-05-12 20:25:06 +02:00
parent 76907a8e3d
commit ff64557d29
6 changed files with 39 additions and 379 deletions

4
examples/lang_c/.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
.idea
out
rust-target
include

View file

@ -1,23 +0,0 @@
cmake_minimum_required(VERSION 3.28)
project(lang_c C)
set(CMAKE_C_STANDARD 17)
include(FetchContent)
FetchContent_Declare(
Corrosion
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
GIT_TAG v0.5 # Optionally specify a commit hash, version tag or branch here
)
FetchContent_MakeAvailable(Corrosion)
# Import targets defined in a package or workspace manifest `Cargo.toml` file
corrosion_import_crate(
MANIFEST_PATH ../../servicepoint2/Cargo.toml
PROFILE release
FEATURES c-api
ALL_FEATURES)
add_executable(lang_c main.c)
target_link_libraries(lang_c PRIVATE servicepoint2)

23
examples/lang_c/Makefile Normal file
View file

@ -0,0 +1,23 @@
ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
RUST_TARGET_DIR := ${ROOT_DIR}rust-target
export SP2_INCLUDE_DIR := ${ROOT_DIR}sp2
OUT_DIR := ${ROOT_DIR}out
.PHONY: clean
run: ${OUT_DIR}/lang_c
out/lang_c
all: ${OUT_DIR}/lang_c
${OUT_DIR}/lang_c: ${SP2_INCLUDE_DIR}/sp2-bindings.h main.c
mkdir -p ${OUT_DIR}
gcc ${SP2_INCLUDE_DIR}/sp2-bindings.h main.c -L ${RUST_TARGET_DIR}/release/ -Wl,-Bstatic -l servicepoint2 -Wl,-Bdynamic -o ${OUT_DIR}/lang_c --verbose
${SP2_INCLUDE_DIR}/sp2-bindings.h:
cd ../../servicepoint2/ && cargo build --release --target-dir ${RUST_TARGET_DIR} --all-features
clean:
rm -r ${SP2_INCLUDE_DIR} || true
rm -r ${OUT_DIR} || true
rm -r ${RUST_TARGET_DIR} || true

View file

@ -1,5 +1,5 @@
#include <stdio.h>
#include "../../servicepoint2/sp2-bindings.h"
#include "sp2/sp2-bindings.h"
int main(void) {
sp2_Connection *connection = sp2_connection_open("localhost:2342");