Skip to content

Commit 8c44301

Browse files
authored
Merge pull request #2838 from ruby/crate-io
Add crate metadata
2 parents 859362a + ff6d9b7 commit 8c44301

4 files changed

Lines changed: 54 additions & 9 deletions

File tree

rust/ruby-rbs-sys/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
name = "ruby-rbs-sys"
33
version = "0.1.0"
44
edition = "2024"
5+
license = "BSD-2-Clause"
6+
description = "Low-level FFI bindings for RBS -- the type signature language for Ruby programs"
7+
homepage = "https://github.com/ruby/rbs"
8+
repository = "https://github.com/ruby/rbs.git"
9+
readme = "../../README.md"
510

611
[lib]
712
doctest = false

rust/ruby-rbs-sys/build.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,36 @@ fn build(include_dir: &Path, src_dir: &Path) -> Result<(), Box<dyn Error>> {
3333
}
3434

3535
fn root_dir() -> Result<PathBuf, Box<dyn Error>> {
36-
Ok(Path::new(env!("CARGO_MANIFEST_DIR"))
37-
.ancestors()
38-
.nth(2)
39-
.ok_or("Failed to find project root directory")?
40-
.to_path_buf())
36+
// Allow overriding via environment variable (useful for packaging)
37+
if let Ok(source_dir) = env::var("RBS_SOURCE_DIR") {
38+
let root = PathBuf::from(source_dir);
39+
let include_dir = root.join("include");
40+
let src_dir = root.join("src");
41+
42+
if include_dir.exists() && src_dir.exists() {
43+
return Ok(root);
44+
} else {
45+
return Err(format!(
46+
"RBS_SOURCE_DIR is set to {:?}, but include/ and src/ directories not found",
47+
root
48+
)
49+
.into());
50+
}
51+
}
52+
53+
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
54+
55+
// Try workspace structure (development)
56+
if let Some(workspace_root) = manifest_dir.ancestors().nth(2) {
57+
let include_dir = workspace_root.join("include");
58+
let src_dir = workspace_root.join("src");
59+
60+
if include_dir.exists() && src_dir.exists() {
61+
return Ok(workspace_root.to_path_buf());
62+
}
63+
}
64+
65+
Err("Cannot find include/ and src/ directories. Set RBS_SOURCE_DIR environment variable to the repository root.".into())
4166
}
4267

4368
fn source_files<P: AsRef<Path>>(root_dir: P) -> Result<Vec<String>, Box<dyn Error>> {

rust/ruby-rbs/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
name = "ruby-rbs"
33
version = "0.1.0"
44
edition = "2024"
5+
license = "BSD-2-Clause"
6+
description = "Rust bindings for RBS -- the type signature language for Ruby programs"
7+
homepage = "https://github.com/ruby/rbs"
8+
repository = "https://github.com/ruby/rbs.git"
9+
readme = "../../README.md"
510

611
[dependencies]
7-
ruby-rbs-sys = { path = "../ruby-rbs-sys" }
12+
ruby-rbs-sys = { version = "0.1", path = "../ruby-rbs-sys" }
813

914
[build-dependencies]
1015
serde = { version = "1.0", features = ["derive"] }

rust/ruby-rbs/build.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,19 @@ impl Node {
5151
}
5252

5353
fn main() -> Result<(), Box<dyn Error>> {
54-
let config_path = Path::new(env!("CARGO_MANIFEST_DIR"))
55-
.join("../../config.yml")
56-
.canonicalize()?;
54+
// Allow overriding the source directory via environment variable (useful for packaging)
55+
let config_path = if let Ok(source_dir) = env::var("RBS_SOURCE_DIR") {
56+
Path::new(&source_dir).join("config.yml")
57+
} else {
58+
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../config.yml")
59+
};
60+
61+
let config_path = config_path.canonicalize().map_err(|e| {
62+
format!(
63+
"Failed to find config.yml at {:?}: {}. Set RBS_SOURCE_DIR environment variable to the repository root.",
64+
config_path, e
65+
)
66+
})?;
5767

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

0 commit comments

Comments
 (0)