This commit is contained in:
parent
2f7a2dfd62
commit
c069c1966b
96 changed files with 97 additions and 12420 deletions
14
examples/lang_c/Cargo.toml
Normal file
14
examples/lang_c/Cargo.toml
Normal file
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "lang_c"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
test = false
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.2"
|
||||
|
||||
[dependencies]
|
||||
servicepoint_binding_c = { path = "../.." }
|
34
examples/lang_c/Makefile
Normal file
34
examples/lang_c/Makefile
Normal file
|
@ -0,0 +1,34 @@
|
|||
CC := gcc
|
||||
|
||||
THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||
REPO_ROOT := $(THIS_DIR)/../../../..
|
||||
|
||||
build: out/lang_c
|
||||
|
||||
clean:
|
||||
rm -r out || true
|
||||
rm include/servicepoint.h || true
|
||||
cargo clean
|
||||
|
||||
run: out/lang_c
|
||||
out/lang_c
|
||||
|
||||
PHONY: build clean dependencies run
|
||||
|
||||
out/lang_c: dependencies src/main.c
|
||||
mkdir -p out || true
|
||||
${CC} src/main.c \
|
||||
-I include \
|
||||
-L $(REPO_ROOT)/target/release \
|
||||
-Wl,-Bstatic -lservicepoint_binding_c \
|
||||
-Wl,-Bdynamic -llzma \
|
||||
-o out/lang_c
|
||||
|
||||
dependencies: FORCE
|
||||
mkdir -p include || true
|
||||
# generate servicepoint header and binary to link against
|
||||
SERVICEPOINT_HEADER_OUT=$(THIS_DIR)/include cargo build \
|
||||
--manifest-path=$(REPO_ROOT)/crates/servicepoint_binding_c/Cargo.toml \
|
||||
--release
|
||||
|
||||
FORCE: ;
|
17
examples/lang_c/build.rs
Normal file
17
examples/lang_c/build.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
const SP_INCLUDE: &str = "DEP_SERVICEPOINT_INCLUDE";
|
||||
|
||||
fn main() {
|
||||
println!("cargo::rerun-if-changed=src/main.c");
|
||||
println!("cargo::rerun-if-changed=build.rs");
|
||||
println!("cargo::rerun-if-env-changed={SP_INCLUDE}");
|
||||
|
||||
let sp_include =
|
||||
std::env::var_os(SP_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.opt_level(2);
|
||||
cc.compile("lang_c");
|
||||
}
|
1867
examples/lang_c/include/servicepoint.h
Normal file
1867
examples/lang_c/include/servicepoint.h
Normal file
File diff suppressed because it is too large
Load diff
1
examples/lang_c/src/lib.rs
Normal file
1
examples/lang_c/src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
|||
|
17
examples/lang_c/src/main.c
Normal file
17
examples/lang_c/src/main.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include <stdio.h>
|
||||
#include "servicepoint.h"
|
||||
|
||||
int main(void) {
|
||||
SPConnection *connection = sp_connection_open("localhost:2342");
|
||||
if (connection == NULL)
|
||||
return 1;
|
||||
|
||||
SPBitmap *pixels = sp_bitmap_new(SP_PIXEL_WIDTH, SP_PIXEL_HEIGHT);
|
||||
sp_bitmap_fill(pixels, true);
|
||||
|
||||
SPCommand *command = sp_command_bitmap_linear_win(0, 0, pixels, SP_COMPRESSION_CODE_UNCOMPRESSED);
|
||||
sp_connection_send_command(connection, command);
|
||||
|
||||
sp_connection_free(connection);
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue