diff --git a/README.md b/README.md index 2f089d3..4788c75 100644 --- a/README.md +++ b/README.md @@ -43,32 +43,37 @@ Please specify the full version including patch in your Cargo.toml until 1.0 is ## Installation -1. Add this repo as a submodule: - ```bash - git submodule add https://git.berlin.ccc.de/servicepoint/servicepoint-binding-c.git - git commit -m "add servicepoint-binding-c submodule" - ``` -2. Add a build step for the servicepoint library. If you use make, this could look something like this: - ``` - dependencies: FORCE - cargo build --manifest-path=servicepoint-binding-c/Cargo.toml --release - FORCE: ; - ``` -3. Link against the library. If you are on linux and linking statically: - ``` - ${CC} main.c \ - -I servicepoint-binding-c/include \ - -L servicepoint-binding-c/target/release \ - -Wl,-Bstatic -lservicepoint_binding_c \ - -Wl,-Bdynamic -llzma \ - -o out/example - ``` +This manual uses gnumake, though it should work similarly for other build systems. + +Add this repo as a submodule: + +```bash +git submodule add https://git.berlin.ccc.de/servicepoint/servicepoint-binding-c.git +git commit -m "add servicepoint-binding-c submodule" +``` + +Update your Makefile: + +```Makefile +# provide header and binary to CC +CFLAGS += -I servicepoint-binding-c/include -L servicepoint-binding-c/target/release +# link statically against servicepoint, link against lzma dynamically +CFLAGS += -Wl,-Bstatic -lservicepoint_binding_c -Wl,-Bdynamic -llzma + +# add target to build rust library - cargo will check for dependency changes +servicepoint-binding-c/target/release/libservicepoint.a: + cargo build --manifest-path=servicepoint-binding-c/Cargo.toml --release + +# add static lib as a dependency for your compilation +# if you build .so files separately, this should be part of your build step +my_bin: $(src) servicepoint-binding-c/target/release/libservicepoint.a + $(CC) $(src) $(CFLAGS) -o $@ +``` You have the choice of linking statically (recommended) or dynamically. - -- The C example shows how to link statically against the `staticlib` variant. -- When linked dynamically, you have to provide the `cdylib` at runtime in the _same_ version, as there are no API/ABI +When linked dynamically, you have to provide the `cdylib` at runtime in the _same_ version, as there are no API/ABI guarantees yet. +The Makefile in the example directory contains a bunch of additional compiler flags you might want to add depending on your use case. ## Notes on differences to rust library diff --git a/example/Makefile b/example/Makefile index f7111b1..32e6091 100644 --- a/example/Makefile +++ b/example/Makefile @@ -101,7 +101,7 @@ clean-rust: $(_unstripped_bins): out/%_unstripped: src/%.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(_sp_artifacts) mkdir -p out || true - ${CC} $< \ + $(CC) $< \ -I $(SERVICEPOINT_HEADER_OUT) \ -L $(RUST_TARGET_DIR) \ $(CCFLAGS) \ @@ -113,7 +113,7 @@ $(_bins): out/%: out/%_unstripped $(_sp_artifacts): $(_rs_src) mkdir -p $(SERVICEPOINT_HEADER_OUT) || true # generate servicepoint header and library to link against - ${CARGO} rustc $(CARGOFLAGS) -- $(RUSTFLAGS) + $(CARGO) rustc $(CARGOFLAGS) -- $(RUSTFLAGS) $(_run_programs): run_%: out/% FORCE ./$< diff --git a/flake.nix b/flake.nix index 5224259..82983f7 100644 --- a/flake.nix +++ b/flake.nix @@ -37,7 +37,6 @@ xe xz libgcc - musl libunwind pkgsStatic.musl ];