The Demo That Automatically Generates Rust Static Link Bindings For The C Project With bindgen and cc::Builder #2588
Euraxluo
started this conversation in
Show and tell
Replies: 1 comment
-
code on repo:Euraxluo/LKH-rs@0694fa4 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have created a small demo project to showcase how to generate Rust static linking bindings for C projects. I have tested the project with the gcc compiler on Unix and the cl compiler on Windows, and it seems to be working fine.
PS:This is my pre-research for creating rust bindings for the LKH-3
the C project named LKHDemo in source_code dir:
.
├── CMakeLists.txt
├── Makefile
├── SRC
│ ├── GetTime.c
│ ├── INCLUDE
│ │ ├── demo.h
│ │ └── demo2.h
│ ├── LKHmain.c
│ ├── Makefile
│ ├── demo.c
│ └── demo2.c
└── test.sh
content:
file_name:.gitignore
file_name:CMakeLists.txt
file_name:Makefile
file_name:demo.c
file_name:demo2.c
file_name:GetTime.c
file_name:demo.h
file_name:demo2.h
file_name:LKHmain.c
file_name:Makefile
rust project tree:
.
├── Cargo.lock
├── Cargo.toml
├── READMD.md
├── build.rs
├── build.yaml
├── source_code
│ ├── LKHDemo
│ └── wrapper.h
└── src
├── bindings.rs
├── lib.rs
└── main.rs
the bindings.rs and wrapper.h is auto gen!
src code:
file_name:src/lib.rs
file_name:src/main.rs
at cargo.toml dir,file content there
file_name:build.rs
file_name:Unix build.yaml
file_name:windows build.yaml
PS:if in windows ,you want use gcc,you must change cc::Builder compile flag,the default
-Fo
flag Not in line with expectations,you can use command mod use ccfile_name:Cargo.toml
test in WSL:
test in OSX(m2):
test in windows:
Beta Was this translation helpful? Give feedback.
All reactions