orbit2-buildtools

Crates.ioorbit2-buildtools
lib.rsorbit2-buildtools
version0.1.1-alpha.2
sourcesrc
created_at2024-06-25 12:09:21.054234
updated_at2024-06-26 19:19:05.571394
descriptionSome tools to build some Corba binding from IDLs using orbit2-sys
homepagehttps://github.com/jeteve/orbit2-rs
repository
max_upload_size
id1283270
size15,569
Jerome Eteve (jeteve)

documentation

README

How to build a common IDL lib (no service code, just types and client)

For the rest of this readme, we assume that your library containing your IDLs binding is called $PROJECT_IDLS_NAME. We'll also work from an example echo.idl to illustrate how to build the binding.

Make a new lib

cargo new --lib $PROJECT_IDLS_NAME
cd $PROJECT_IDLS_NAME

Depends on this, in your Cargo.toml, as well as orbit2-sys as a standard dependency

[dependencies]
orbit2-sys = ">=0.1.0"

[build-dependencies]
orbit2-buildtools = ">=0.1.0"

Add your idls in 'static'

$ mkdir static/
# And put your IDL(s?), for instance:
$ cat static/echo.idl 
interface Echo {
    void echoString(in string input);
};

Make a build.rs to compile the idl

Example build.rs (assuming echo.idl)

use std::path::PathBuf;

use orbit2_buildtools::CommonBuilder;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let idl_path = PathBuf::from("static/echo.idl");
    let out_path = PathBuf::from(std::env::var("OUT_DIR").unwrap());

    // generate the C code plus the Rust binding
    // Note the name of the service is the toplevel name in your IDL
    let r = CommonBuilder::new("Echo")
        .idl_file(&idl_path)
        .out_path(&out_path)
        .generate()?;

    // make the binding path available in the rest of the compilation
    println!(
        "cargo:rustc-env=ECHO_IDL_BINDING={:?}",
        r.binding_file.as_path()
    );

    Ok(())
}

Structure the generated code in your lib.rs (or a submodule if you wish too)


use orbit2_sys::core::*;
include!(env!("ECHO_IDL_BINDING"));

And that's it. Now you can use your module in your client and server applications.

Commit count: 0

cargo fmt