diff --git a/Cargo.lock b/Cargo.lock
index 7eed9c8..2dac4bc 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -389,7 +389,7 @@ name = "lang_c"
version = "0.1.0"
dependencies = [
"cc",
- "servicepoint",
+ "servicepoint_binding_c",
]
[[package]]
diff --git a/crates/servicepoint/Cargo.toml b/crates/servicepoint/Cargo.toml
index 3991728..8e7fb65 100644
--- a/crates/servicepoint/Cargo.toml
+++ b/crates/servicepoint/Cargo.toml
@@ -7,7 +7,7 @@ license = "GPL-3.0-or-later"
description = "A rust library for the CCCB Service Point Display."
homepage = "https://docs.rs/crate/servicepoint"
repository = "https://github.com/cccb/servicepoint"
-readme = "../README.md"
+readme = "../../README.md"
[lib]
crate-type = ["staticlib", "rlib", "cdylib"]
diff --git a/crates/servicepoint_binding_c/Cargo.toml b/crates/servicepoint_binding_c/Cargo.toml
index 79ab5b9..9a2cb27 100644
--- a/crates/servicepoint_binding_c/Cargo.toml
+++ b/crates/servicepoint_binding_c/Cargo.toml
@@ -7,7 +7,8 @@ license = "GPL-3.0-or-later"
description = "C bindings for the servicepoint crate."
homepage = "https://docs.rs/crate/servicepoint"
repository = "https://github.com/cccb/servicepoint"
-readme = "../README.md"
+readme = "../../README.md"
+links = "servicepoint"
[build-dependencies]
cbindgen = "0.26.0"
diff --git a/crates/servicepoint_binding_c/build.rs b/crates/servicepoint_binding_c/build.rs
index 6ed5849..f5e4607 100644
--- a/crates/servicepoint_binding_c/build.rs
+++ b/crates/servicepoint_binding_c/build.rs
@@ -1,13 +1,28 @@
-use std::env;
+use std::{env, fs::copy};
use cbindgen::{generate_with_config, Config};
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
- let config = Config::from_file(crate_dir.clone() + "/cbindgen.toml").unwrap();
+ println!("cargo::rerun-if-changed={crate_dir}");
+
+ let config =
+ Config::from_file(crate_dir.clone() + "/cbindgen.toml").unwrap();
let servicepoint_dir = crate_dir.clone() + "/../servicepoint";
+ let output_dir = env::var("OUT_DIR").unwrap();
+ let header_file = output_dir.clone() + "/servicepoint.h";
+
generate_with_config(servicepoint_dir, config)
- .unwrap()
- .write_to_file("servicepoint.h");
+ .unwrap()
+ .write_to_file(&header_file);
+ println!("cargo:include={output_dir}");
+
+ println!("cargo::rerun-if-env-changed=SERVICEPOINT_HEADER_OUT");
+ if let Ok(header_out) = env::var("SERVICEPOINT_HEADER_OUT") {
+ let header_copy = header_out + "/servicepoint.h";
+ println!("cargo:warning=Copying header to {header_copy}");
+ copy(header_file, &header_copy).unwrap();
+ println!("cargo::rerun-if-changed={header_copy}");
+ }
}
diff --git a/crates/servicepoint_binding_cs/Cargo.toml b/crates/servicepoint_binding_cs/Cargo.toml
index 8cedffc..ed651f5 100644
--- a/crates/servicepoint_binding_cs/Cargo.toml
+++ b/crates/servicepoint_binding_cs/Cargo.toml
@@ -3,6 +3,7 @@ name = "servicepoint_binding_cs"
version = "0.4.2"
edition = "2021"
publish = false
+readme = "../../README.md"
[lib]
crate-type = ["cdylib"]
diff --git a/crates/servicepoint_binding_cs/src/BindGen/ServicePoint2.g.cs b/crates/servicepoint_binding_cs/src/BindGen/ServicePoint2.g.cs
deleted file mode 100644
index d138126..0000000
--- a/crates/servicepoint_binding_cs/src/BindGen/ServicePoint2.g.cs
+++ /dev/null
@@ -1,286 +0,0 @@
-//
-// This code is generated by csbindgen.
-// DON'T CHANGE THIS DIRECTLY.
-//
-#pragma warning disable CS8500
-#pragma warning disable CS8981
-using System;
-using System.Runtime.InteropServices;
-
-
-namespace ServicePoint.BindGen
-{
- public static unsafe partial class NativeMethods
- {
- const string __DllName = "servicepoint";
-
-
-
- /// Creates a new `BitVec` instance. The returned instance has to be freed with `bit_vec_dealloc`.
- [DllImport(__DllName, EntryPoint = "sp2_bit_vec_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern BitVec* sp2_bit_vec_new(nuint size);
-
- /// Loads a `BitVec` from the provided data. The returned instance has to be freed with `bit_vec_dealloc`.
- [DllImport(__DllName, EntryPoint = "sp2_bit_vec_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern BitVec* sp2_bit_vec_load(byte* data, nuint data_length);
-
- /// Clones a `BitVec`. The returned instance has to be freed with `bit_vec_dealloc`.
- [DllImport(__DllName, EntryPoint = "sp2_bit_vec_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern BitVec* sp2_bit_vec_clone(BitVec* @this);
-
- /// Deallocates a `BitVec`. Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
- [DllImport(__DllName, EntryPoint = "sp2_bit_vec_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void sp2_bit_vec_dealloc(BitVec* @this);
-
- /// Gets the value of a bit from the `BitVec`.
- [DllImport(__DllName, EntryPoint = "sp2_bit_vec_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- [return: MarshalAs(UnmanagedType.U1)]
- public static extern bool sp2_bit_vec_get(BitVec* @this, nuint index);
-
- /// Sets the value of a bit in the `BitVec`.
- [DllImport(__DllName, EntryPoint = "sp2_bit_vec_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- [return: MarshalAs(UnmanagedType.U1)]
- public static extern bool sp2_bit_vec_set(BitVec* @this, nuint index, [MarshalAs(UnmanagedType.U1)] bool value);
-
- /// Sets the value of all bits in the `BitVec`.
- [DllImport(__DllName, EntryPoint = "sp2_bit_vec_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void sp2_bit_vec_fill(BitVec* @this, [MarshalAs(UnmanagedType.U1)] bool value);
-
- /// Gets the length of the `BitVec` in bits.
- [DllImport(__DllName, EntryPoint = "sp2_bit_vec_len", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern nuint sp2_bit_vec_len(BitVec* @this);
-
- /// Returns true if length is 0.
- [DllImport(__DllName, EntryPoint = "sp2_bit_vec_is_empty", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- [return: MarshalAs(UnmanagedType.U1)]
- public static extern bool sp2_bit_vec_is_empty(BitVec* @this);
-
- /// Gets an unsafe reference to the data of the `BitVec` instance. ## Safety The caller has to make sure to never access the returned memory after the `BitVec` instance has been consumed or manually deallocated. Reading and writing concurrently to either the original instance or the returned data will result in undefined behavior.
- [DllImport(__DllName, EntryPoint = "sp2_bit_vec_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern CByteSlice sp2_bit_vec_unsafe_data_ref(BitVec* @this);
-
- /// Creates a new `ByteGrid` instance. The returned instance has to be freed with `byte_grid_dealloc`.
- [DllImport(__DllName, EntryPoint = "sp2_byte_grid_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern ByteGrid* sp2_byte_grid_new(nuint width, nuint height);
-
- /// Loads a `ByteGrid` with the specified dimensions from the provided data. The returned instance has to be freed with `byte_grid_dealloc`.
- [DllImport(__DllName, EntryPoint = "sp2_byte_grid_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern ByteGrid* sp2_byte_grid_load(nuint width, nuint height, byte* data, nuint data_length);
-
- /// Clones a `ByteGrid`. The returned instance has to be freed with `byte_grid_dealloc`.
- [DllImport(__DllName, EntryPoint = "sp2_byte_grid_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern ByteGrid* sp2_byte_grid_clone(ByteGrid* @this);
-
- /// Deallocates a `ByteGrid`. Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
- [DllImport(__DllName, EntryPoint = "sp2_byte_grid_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void sp2_byte_grid_dealloc(ByteGrid* @this);
-
- /// Get the current value at the specified position
- [DllImport(__DllName, EntryPoint = "sp2_byte_grid_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern byte sp2_byte_grid_get(ByteGrid* @this, nuint x, nuint y);
-
- /// Sets the current value at the specified position
- [DllImport(__DllName, EntryPoint = "sp2_byte_grid_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void sp2_byte_grid_set(ByteGrid* @this, nuint x, nuint y, byte value);
-
- /// Fills the whole `ByteGrid` with the specified value
- [DllImport(__DllName, EntryPoint = "sp2_byte_grid_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void sp2_byte_grid_fill(ByteGrid* @this, byte value);
-
- /// Gets the width in pixels of the `ByteGrid` instance.
- [DllImport(__DllName, EntryPoint = "sp2_byte_grid_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern nuint sp2_byte_grid_width(ByteGrid* @this);
-
- /// Gets the height in pixels of the `ByteGrid` instance.
- [DllImport(__DllName, EntryPoint = "sp2_byte_grid_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern nuint sp2_byte_grid_height(ByteGrid* @this);
-
- /// Gets an unsafe reference to the data of the `ByteGrid` instance. ## Safety The caller has to make sure to never access the returned memory after the `ByteGrid` instance has been consumed or manually deallocated. Reading and writing concurrently to either the original instance or the returned data will result in undefined behavior.
- [DllImport(__DllName, EntryPoint = "sp2_byte_grid_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern CByteSlice sp2_byte_grid_unsafe_data_ref(ByteGrid* @this);
-
- /// Tries to turn a `Packet` into a `Command`. The packet is gets deallocated in the process. Returns: pointer to command or NULL
- [DllImport(__DllName, EntryPoint = "sp2_command_try_from_packet", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Command* sp2_command_try_from_packet(Packet* packet);
-
- /// Clones a `Command` instance
- [DllImport(__DllName, EntryPoint = "sp2_command_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Command* sp2_command_clone(Command* original);
-
- /// Allocates a new `Command::Clear` instance
- [DllImport(__DllName, EntryPoint = "sp2_command_clear", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Command* sp2_command_clear();
-
- /// Allocates a new `Command::HardReset` instance
- [DllImport(__DllName, EntryPoint = "sp2_command_hard_reset", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Command* sp2_command_hard_reset();
-
- /// Allocates a new `Command::FadeOut` instance
- [DllImport(__DllName, EntryPoint = "sp2_command_fade_out", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Command* sp2_command_fade_out();
-
- /// Allocates a new `Command::Brightness` instance
- [DllImport(__DllName, EntryPoint = "sp2_command_brightness", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Command* sp2_command_brightness(byte brightness);
-
- /// Allocates a new `Command::CharBrightness` instance. The passed `ByteGrid` gets deallocated in the process.
- [DllImport(__DllName, EntryPoint = "sp2_command_char_brightness", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Command* sp2_command_char_brightness(nuint x, nuint y, ByteGrid* byte_grid);
-
- /// Allocates a new `Command::BitmapLinear` instance. The passed `BitVec` gets deallocated in the process.
- [DllImport(__DllName, EntryPoint = "sp2_command_bitmap_linear", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Command* sp2_command_bitmap_linear(nuint offset, BitVec* bit_vec, CompressionCode compression);
-
- /// Allocates a new `Command::BitmapLinearAnd` instance. The passed `BitVec` gets deallocated in the process.
- [DllImport(__DllName, EntryPoint = "sp2_command_bitmap_linear_and", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Command* sp2_command_bitmap_linear_and(nuint offset, BitVec* bit_vec, CompressionCode compression);
-
- /// Allocates a new `Command::BitmapLinearOr` instance. The passed `BitVec` gets deallocated in the process.
- [DllImport(__DllName, EntryPoint = "sp2_command_bitmap_linear_or", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Command* sp2_command_bitmap_linear_or(nuint offset, BitVec* bit_vec, CompressionCode compression);
-
- /// Allocates a new `Command::BitmapLinearXor` instance. The passed `BitVec` gets deallocated in the process.
- [DllImport(__DllName, EntryPoint = "sp2_command_bitmap_linear_xor", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Command* sp2_command_bitmap_linear_xor(nuint offset, BitVec* bit_vec, CompressionCode compression);
-
- /// Allocates a new `Command::Cp437Data` instance. The passed `ByteGrid` gets deallocated in the process.
- [DllImport(__DllName, EntryPoint = "sp2_command_cp437_data", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Command* sp2_command_cp437_data(nuint x, nuint y, ByteGrid* byte_grid);
-
- /// Allocates a new `Command::BitmapLinearWin` instance. The passed `PixelGrid` gets deallocated in the process.
- [DllImport(__DllName, EntryPoint = "sp2_command_bitmap_linear_win", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Command* sp2_command_bitmap_linear_win(nuint x, nuint y, PixelGrid* byte_grid, CompressionCode compression_code);
-
- /// Deallocates a `Command`. Note that connection_send does this implicitly, so you only need to do this if you use the library for parsing commands.
- [DllImport(__DllName, EntryPoint = "sp2_command_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void sp2_command_dealloc(Command* ptr);
-
- /// Creates a new instance of Connection. The returned instance has to be deallocated with `connection_dealloc`. returns: NULL if connection fails or connected instance Panics: bad string encoding
- [DllImport(__DllName, EntryPoint = "sp2_connection_open", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Connection* sp2_connection_open(byte* host);
-
- /// Sends the command instance. The instance is consumed / destroyed and cannot be used after this call.
- [DllImport(__DllName, EntryPoint = "sp2_connection_send", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- [return: MarshalAs(UnmanagedType.U1)]
- public static extern bool sp2_connection_send(Connection* connection, Packet* command_ptr);
-
- /// Closes and deallocates a connection instance
- [DllImport(__DllName, EntryPoint = "sp2_connection_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void sp2_connection_dealloc(Connection* ptr);
-
- /// Creates a new `PixelGrid` instance. The returned instance has to be freed with `pixel_grid_dealloc`.
- [DllImport(__DllName, EntryPoint = "sp2_pixel_grid_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern PixelGrid* sp2_pixel_grid_new(nuint width, nuint height);
-
- /// Loads a `PixelGrid` with the specified dimensions from the provided data. The returned instance has to be freed with `pixel_grid_dealloc`.
- [DllImport(__DllName, EntryPoint = "sp2_pixel_grid_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern PixelGrid* sp2_pixel_grid_load(nuint width, nuint height, byte* data, nuint data_length);
-
- /// Clones a `PixelGrid`. The returned instance has to be freed with `pixel_grid_dealloc`.
- [DllImport(__DllName, EntryPoint = "sp2_pixel_grid_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern PixelGrid* sp2_pixel_grid_clone(PixelGrid* @this);
-
- /// Deallocates a `PixelGrid`. Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
- [DllImport(__DllName, EntryPoint = "sp2_pixel_grid_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void sp2_pixel_grid_dealloc(PixelGrid* @this);
-
- /// Get the current value at the specified position
- [DllImport(__DllName, EntryPoint = "sp2_pixel_grid_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- [return: MarshalAs(UnmanagedType.U1)]
- public static extern bool sp2_pixel_grid_get(PixelGrid* @this, nuint x, nuint y);
-
- /// Sets the current value at the specified position
- [DllImport(__DllName, EntryPoint = "sp2_pixel_grid_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void sp2_pixel_grid_set(PixelGrid* @this, nuint x, nuint y, [MarshalAs(UnmanagedType.U1)] bool value);
-
- /// Fills the whole `PixelGrid` with the specified value
- [DllImport(__DllName, EntryPoint = "sp2_pixel_grid_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void sp2_pixel_grid_fill(PixelGrid* @this, [MarshalAs(UnmanagedType.U1)] bool value);
-
- /// Gets the width in pixels of the `PixelGrid` instance.
- [DllImport(__DllName, EntryPoint = "sp2_pixel_grid_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern nuint sp2_pixel_grid_width(PixelGrid* @this);
-
- /// Gets the height in pixels of the `PixelGrid` instance.
- [DllImport(__DllName, EntryPoint = "sp2_pixel_grid_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern nuint sp2_pixel_grid_height(PixelGrid* @this);
-
- /// Gets an unsafe reference to the data of the `PixelGrid` instance. ## Safety The caller has to make sure to never access the returned memory after the `PixelGrid` instance has been consumed or manually deallocated. Reading and writing concurrently to either the original instance or the returned data will result in undefined behavior.
- [DllImport(__DllName, EntryPoint = "sp2_pixel_grid_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern CByteSlice sp2_pixel_grid_unsafe_data_ref(PixelGrid* @this);
-
- /// Turns a `Command` into a `Packet`. The command gets deallocated in the process.
- [DllImport(__DllName, EntryPoint = "sp2_packet_from_command", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Packet* sp2_packet_from_command(Command* command);
-
- /// Tries to load a `Packet` from the passed array with the specified length. returns: NULL in case of an error, pointer to the allocated packet otherwise
- [DllImport(__DllName, EntryPoint = "sp2_packet_try_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern Packet* sp2_packet_try_load(byte* data, nuint length);
-
- /// Deallocates a `Packet`. Note: do not call this if the instance has been consumed in another way, e.g. by sending it.
- [DllImport(__DllName, EntryPoint = "sp2_packet_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern void sp2_packet_dealloc(Packet* @this);
-
-
- }
-
- [StructLayout(LayoutKind.Sequential)]
- public unsafe partial struct BitVec
- {
- }
-
- [StructLayout(LayoutKind.Sequential)]
- public unsafe partial struct ByteGrid
- {
- }
-
- [StructLayout(LayoutKind.Sequential)]
- public unsafe partial struct Connection
- {
- }
-
- [StructLayout(LayoutKind.Sequential)]
- public unsafe partial struct PixelGrid
- {
- }
-
- [StructLayout(LayoutKind.Sequential)]
- public unsafe partial struct CByteSlice
- {
- public byte* start;
- public nuint length;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- public unsafe partial struct Packet
- {
- }
-
-
- public enum Command
- {
- Clear,
- HardReset,
- FadeOut,
- CharBrightness,
- Brightness,
- BitmapLegacy,
- BitmapLinear,
- BitmapLinearAnd,
- BitmapLinearOr,
- BitmapLinearXor,
- Cp437Data,
- BitmapLinearWin,
- }
-
- public enum CompressionCode : ushort
- {
- Uncompressed = 0,
- Zlib = 26490,
- Bzip2 = 25210,
- Lzma = 27770,
- Zstd = 31347,
- }
-
-
-}
diff --git a/examples/lang_c/Cargo.toml b/examples/lang_c/Cargo.toml
index 5b7dc6e..8baf474 100644
--- a/examples/lang_c/Cargo.toml
+++ b/examples/lang_c/Cargo.toml
@@ -4,10 +4,8 @@ version = "0.1.0"
edition = "2021"
publish = false
-[lib]
-
[build-dependencies]
cc = "1.0"
[dependencies]
-servicepoint = { path = "../../crates/servicepoint" }
+servicepoint_binding_c = { path = "../../crates/servicepoint_binding_c" }
diff --git a/examples/lang_c/Makefile b/examples/lang_c/Makefile
index 489db4c..825510a 100644
--- a/examples/lang_c/Makefile
+++ b/examples/lang_c/Makefile
@@ -1,22 +1,36 @@
-ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
-OUT_DIR := ${ROOT_DIR}/out
+CC := gcc
-SP2_DIR := ${ROOT_DIR}/../../servicepoint
-SP2_INCLUDE := ${ROOT_DIR}/../../servicepoint-binding-c
-SP2_TARGET_RELEASE := ${SP2_DIR}/target/release
+THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
+REPO_ROOT := $(THIS_DIR)/../..
-.PHONY: build run clean
-
-all: ${OUT_DIR}/lang_c
-
-run: ${OUT_DIR}/lang_c
- out/lang_c
+build: out/lang_c
clean:
- rm -r ${OUT_DIR} || true
- rm -r ${SP2_TARGET_RELEASE} || true
+ rm -r out
+ rm include/servicepoint.h
-${OUT_DIR}/lang_c: main.c
- cd ${SP2_DIR} && cargo build --release --all-features
- mkdir -p ${OUT_DIR}
- gcc main.c -I ${SP2_INCLUDE} -L ${SP2_TARGET_RELEASE} -Wl,-Bstatic -lservicepoint -Wl,-Bdynamic -o ${OUT_DIR}/lang_c
+run: out/lang_c
+ out/lang_c
+
+PHONY: build clean dependencies run
+
+out/lang_c: dependencies src/main.c
+ mkdir out || true
+ ${CC} src/main.c \
+ -I include \
+ -L $(REPO_ROOT)/target/release \
+ -Wl,-Bstatic -lservicepoint \
+ -Wl,-Bdynamic -llzma \
+ -o out/lang_c \
+
+dependencies: FORCE
+ mkdir include || true
+ # generate servicepoint header
+ SERVICEPOINT_HEADER_OUT=$(THIS_DIR)/include cargo build \
+ --manifest-path=$(REPO_ROOT)/crates/servicepoint_binding_c/Cargo.toml
+
+ # build release binary to link against
+ cargo build --manifest-path=$(REPO_ROOT)/crates/servicepoint/Cargo.toml --release \
+ --features c_api,all_compressions
+
+FORCE: ;
diff --git a/examples/lang_c/build.rs b/examples/lang_c/build.rs
index ff2c59c..56b5b89 100644
--- a/examples/lang_c/build.rs
+++ b/examples/lang_c/build.rs
@@ -1,8 +1,15 @@
-
fn main() {
println!("cargo::rerun-if-changed=src/main.c");
+ println!("cargo::rerun-if-changed=build.rs");
- cc::Build::new()
- .file("src/main.c")
- .compile("lang_c");
+ let sp_include = std::env::var_os("DEP_SERVICEPOINT_INCLUDE")
+ .unwrap()
+ .into_string()
+ .unwrap();
+
+ // this builds a lib, this is only to check that the example compiles
+ let mut cc = cc::Build::new();
+ cc.file("src/main.c");
+ cc.include(&sp_include);
+ cc.compile("lang_c");
}
diff --git a/crates/servicepoint_binding_c/servicepoint.h b/examples/lang_c/include/servicepoint.h
similarity index 100%
rename from crates/servicepoint_binding_c/servicepoint.h
rename to examples/lang_c/include/servicepoint.h
diff --git a/shell.nix b/shell.nix
index c961482..0555690 100644
--- a/shell.nix
+++ b/shell.nix
@@ -1,4 +1,11 @@
-{ pkgs ? import {} }:
- pkgs.mkShell {
- nativeBuildInputs = with pkgs.buildPackages; [ rustup pkg-config xe lzma cargo-tarpaulin ];
+{pkgs ? import {}}:
+pkgs.mkShell {
+ nativeBuildInputs = with pkgs.buildPackages; [
+ rustup
+ pkg-config
+ xe
+ lzma
+ cargo-tarpaulin
+ gnumake
+ ];
}