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
4 changes: 2 additions & 2 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion rust/ruby-rbs-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
[package]
name = "ruby-rbs-sys"
version = "0.1.0"
version = "0.1.1"
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"
include = [
"src/**/*",
"vendor/**/*",
"build.rs",
"wrapper.h",
"Cargo.toml",
]

[lib]
doctest = false
Expand Down
41 changes: 5 additions & 36 deletions rust/ruby-rbs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use std::{
};

fn main() -> Result<(), Box<dyn Error>> {
let root = root_dir()?;
let include = root.join("include");
let src = root.join("src");
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let vendor_rbs = manifest_dir.join("vendor/rbs");
let include = vendor_rbs.join("include");
let c_src = vendor_rbs.join("src");

build(&include, &src)?;
build(&include, &c_src)?;

let bindings = generate_bindings(&include)?;
write_bindings(&bindings)?;
Expand All @@ -32,38 +33,6 @@ fn build(include_dir: &Path, src_dir: &Path) -> Result<(), Box<dyn Error>> {
Ok(())
}

fn root_dir() -> Result<PathBuf, Box<dyn Error>> {
// 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>> {
let mut files = Vec::new();
Expand Down
1 change: 1 addition & 0 deletions rust/ruby-rbs-sys/vendor/rbs/include
1 change: 1 addition & 0 deletions rust/ruby-rbs-sys/vendor/rbs/src
8 changes: 7 additions & 1 deletion rust/ruby-rbs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
[package]
name = "ruby-rbs"
version = "0.1.0"
version = "0.1.1"
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"
include = [
"src/**/*",
"vendor/**/*",
"build.rs",
"Cargo.toml",
]

[dependencies]
ruby-rbs-sys = { version = "0.1", path = "../ruby-rbs-sys" }
Expand Down
10 changes: 3 additions & 7 deletions rust/ruby-rbs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,12 @@ impl Node {
}

fn main() -> Result<(), Box<dyn Error>> {
// 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 manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let config_path = manifest_dir.join("vendor/rbs/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.",
"Failed to find config.yml at {:?}: {}",
config_path, e
)
})?;
Expand Down
1 change: 1 addition & 0 deletions rust/ruby-rbs/vendor/rbs/config.yml
Loading