Skip to content

jklmnn/gpr-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9c84f5a · Feb 28, 2025

History

67 Commits
Jan 28, 2025
Feb 3, 2023
Dec 1, 2023
Jun 23, 2022
Feb 3, 2023
Jan 28, 2025
Jun 9, 2022
Feb 28, 2025
Jan 28, 2025
Feb 28, 2025

Repository files navigation

gpr-rust

Gpr-Rust is a Rust binding for gpr. its goal is to provide an easy way to integrate Ada sources into the Rust build process. It allows to select and build a GNAT project file by parsing the project and providing all required information to call gprbuild and link the resulting library.

Dependencies

To build this project a working installation of alire is required. You can download Alire here. The build script will automatically download the required dependencies. The toolchain and dependencies used to build this crate are only available for the crates build process. For any Ada projects that are being built with this crate an appropriate toolchain needs to be provided.

Addionally the following native C libraries are required:

  • libgmp-dev
  • libssl-dev

Usage

This library is intended to be used in build scripts. The basic process consists of three steps.

  • Loading the project:
let project = gpr::Project::load(Path::new("/path/to/project.gpr")).unwrap();
  • Building the project:
let output = Command::new("gprbuild")
    .args(project.gprbuild_args().unwrap())
    .stderr(Stdio::inherit())
    .output()
    .unwrap();

if !output.status.success() {
    panic!();
}
  • Providing cargo with the required linker flags:
println!(
    "cargo:rustc-link-search={}",
    project.library_dir().unwrap().to_str().unwrap()
);
println!(
    "cargo:rustc-link-lib={}={}",
    project.library_kind().unwrap(),
    project.library_name().unwrap()
);
  • Additionally it can be helpful to tell cargo that changes in the Ada code also should trigger a rerun:
for dir in project.source_dirs().unwrap() {
    println!(
        "cargo:rerun-if-changed={}", dir.as_str()
    );
}

Gpr-Rust doesn't need much configuration, most of the code needed is boilerplate. If any additional options are required to build the Ada project these can be added as arguments to the gprbuild command.

An example project is located in examples/ada_hello/build.rs. It can be tested by running:

cd examples/ada_hello
LD_LIBRARY_PATH=ada_hello/lib cargo run