This script automates the process of setting up a Cargo project with the bindgen crate installed, generating Rust bindings for a C header file, and creating the necessary build configuration files.
- Python 3.x
- Cargo and Rust installed on your system
- Prerequisites for bindgen (see: https://rust-lang.github.io/rust-bindgen/requirements.html)
To install the package, follow these steps:
- Clone this repository by executing the command:
git clone https://github.com/garychia/bindgen-init.git
- Change the working directory to the cloned repository:
cd bindgen-init
- Install the package using pip:
pip install .
Run the script using the following command:
python -m bindgeninit [project_name] [-b]
- project_name: The name of the Cargo project to be created.
- -b or --bin: (Optional) Generates a Cargo binary project instead of a library project.
The script performs the following steps:
- Creates a new Cargo project with the specified project name.
- Installs the bindgen crate using cargo add.
- Copies the example C header file to the project directory.
- Generates a build.rs file with the necessary configuration for bindgen.
- Modifies the lib.rs file to include the generated bindings.
- Prints a success message.
To customize the build configuration, modify the build.rs file generated by the script. You can specify the directories where required shared libraries are located and link the necessary libraries using the println! statements.
The script includes an example C header file (example.h) in the project directory. You can replace it with your own C header file and modify the build.rs file accordingly.
This script is released under the MIT License.