Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rust/ruby-rbs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
name = "ruby-rbs-sys"
version = "0.1.0"
edition = "2024"
license = "BSD-2-Clause"
description = "Low-level FFI bindings for RBS -- the type signature language for Ruby programs"
homepage = "https://github.com/ruby/rbs"
repository = "https://github.com/ruby/rbs.git"
readme = "../../README.md"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcrocha we should add a README dedicated to the crate and how to use it. Right now we're using the root README which is not super relevant in the context of the crate: https://crates.io/crates/ruby-rbs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'll create an issue to work on it


[lib]
doctest = false
Expand Down
35 changes: 30 additions & 5 deletions rust/ruby-rbs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,36 @@ fn build(include_dir: &Path, src_dir: &Path) -> Result<(), Box<dyn Error>> {
}

fn root_dir() -> Result<PathBuf, Box<dyn Error>> {
Ok(Path::new(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(2)
.ok_or("Failed to find project root directory")?
.to_path_buf())
// Allow overriding via environment variable (useful for packaging)
if let Ok(source_dir) = env::var("RBS_SOURCE_DIR") {
let root = PathBuf::from(source_dir);
let include_dir = root.join("include");
let src_dir = root.join("src");

if include_dir.exists() && src_dir.exists() {
return Ok(root);
} else {
return Err(format!(
"RBS_SOURCE_DIR is set to {:?}, but include/ and src/ directories not found",
root
)
.into());
}
}

let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));

// Try workspace structure (development)
if let Some(workspace_root) = manifest_dir.ancestors().nth(2) {
let include_dir = workspace_root.join("include");
let src_dir = workspace_root.join("src");

if include_dir.exists() && src_dir.exists() {
return Ok(workspace_root.to_path_buf());
}
}

Err("Cannot find include/ and src/ directories. Set RBS_SOURCE_DIR environment variable to the repository root.".into())
}

fn source_files<P: AsRef<Path>>(root_dir: P) -> Result<Vec<String>, Box<dyn Error>> {
Expand Down
7 changes: 6 additions & 1 deletion rust/ruby-rbs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
name = "ruby-rbs"
version = "0.1.0"
edition = "2024"
license = "BSD-2-Clause"
description = "Rust bindings for RBS -- the type signature language for Ruby programs"
homepage = "https://github.com/ruby/rbs"
repository = "https://github.com/ruby/rbs.git"
readme = "../../README.md"

[dependencies]
ruby-rbs-sys = { path = "../ruby-rbs-sys" }
ruby-rbs-sys = { version = "0.1", path = "../ruby-rbs-sys" }

[build-dependencies]
serde = { version = "1.0", features = ["derive"] }
Expand Down
16 changes: 13 additions & 3 deletions rust/ruby-rbs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,19 @@ impl Node {
}

fn main() -> Result<(), Box<dyn Error>> {
let config_path = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../config.yml")
.canonicalize()?;
// Allow overriding the source directory via environment variable (useful for packaging)
let config_path = if let Ok(source_dir) = env::var("RBS_SOURCE_DIR") {
Path::new(&source_dir).join("config.yml")
} else {
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../config.yml")
};

let config_path = config_path.canonicalize().map_err(|e| {
format!(
"Failed to find config.yml at {:?}: {}. Set RBS_SOURCE_DIR environment variable to the repository root.",
config_path, e
)
})?;

println!("cargo:rerun-if-changed={}", config_path.display());

Expand Down