Skip to content

Commit 9f267ef

Browse files
committed
Add ruby-rbs crate
This commit introduces the `ruby-rbs` crate, which will provide a safe, high-level Rust API for the RBS C library. It follows the common Rust pattern of separating the safe wrapper from the `*-sys` crate that provides the raw FFI bindings. The `ruby-rbs` crate will depend on `ruby-rbs-sys` for the unsafe C bindings and will expose a safe, idiomatic Rust interface. This commit sets up the foundation for that structure. The initial implementation includes: - The basic crate structure with its own Cargo.toml, declaring a dependency on `ruby-rbs-sys`. - A build script (`build.rs`) that will be responsible for generating safe Rust wrappers from the C API. Currently, it only generates an empty `bindings.rs` file. - The `ruby-rbs` crate is added to the main workspace `Cargo.toml`. While the interaction is not yet implemented, this setup paves the way for providing a robust Rust interface for RBS, which will improve safety and developer experience.
1 parent 4f43565 commit 9f267ef

5 files changed

Lines changed: 41 additions & 0 deletions

File tree

rust/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[workspace]
22
members = [
3+
"ruby-rbs",
34
"ruby-rbs-sys",
45
]
56

rust/ruby-rbs/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "ruby-rbs"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
ruby-rbs-sys = { path = "../ruby-rbs-sys" }

rust/ruby-rbs/build.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use std::env;
2+
use std::fs::File;
3+
use std::io::Write;
4+
use std::path::Path;
5+
6+
fn main() {
7+
println!("cargo:warning=Build script is running!");
8+
9+
if let Err(err) = generate() {
10+
panic!("build.rs failed: {err}");
11+
}
12+
}
13+
14+
fn generate() -> Result<(), Box<dyn std::error::Error>> {
15+
let out_dir = env::var("OUT_DIR").unwrap();
16+
let dest_path = Path::new(&out_dir).join("bindings.rs");
17+
18+
let mut file = File::create(&dest_path)?;
19+
20+
writeln!(file, "// Generated by build.rs")?;
21+
writeln!(file, "// Do not edit this file directly")?;
22+
writeln!(file, "")?;
23+
24+
Ok(())
25+
}

rust/ruby-rbs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)