Skip to content

Commit 3c6a8c9

Browse files
committed
Update publishing
1 parent b6930d8 commit 3c6a8c9

34 files changed

+1179
-895
lines changed

.github/workflows/publish-book.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ on:
88
push:
99
branches:
1010
- main
11+
- better-docs
1112

1213
jobs:
1314
deploy:
14-
runs-on: ubuntu-20.04
15+
runs-on: ubuntu-24.04
1516
concurrency:
1617
group: ${{ github.workflow }}-${{ github.ref }}
1718
steps:
1819
- uses: actions/checkout@v4
1920

20-
- name: Setup mdBook
21-
uses: peaceiris/actions-mdbook@v2
21+
- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
2222
with:
23-
mdbook-version: "0.4.18"
23+
ruby-version: "3.4"
24+
bundler-cache: true
25+
cargo-cache: true
2426

2527
- name: Build the book
26-
run: mdbook build ./book
28+
run: bundle exec rake book:build
2729

2830
- name: Deploy
2931
uses: peaceiris/actions-gh-pages@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ gem/docs
55
.yardoc/
66
.DS_Store
77
examples/rust_reverse/ext/rust_reverse/Cargo.lock
8+
book/src/https:/

book/README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
# The Ruby on Rust Book
22

3-
This directory contains the source for "The Ruby on Rust Book" which is built using [mdBook](https://rust-lang.github.io/mdBook/).
3+
This directory contains the source for "The Ruby on Rust Book" which is built using
4+
[mdBook](https://rust-lang.github.io/mdBook/).
45

56
## SEO Setup
67

78
This book has been configured with SEO optimizations:
89

9-
1. **Meta Tags**: The theme has been updated to include proper meta tags for SEO, including Open Graph and Twitter card support.
10-
11-
2. **Sitemap Generation**: A custom Python script (`generate_sitemap.py`) generates a sitemap.xml file after the book is built.
12-
10+
1. **Meta Tags**: The theme has been updated to include proper meta tags for SEO, including Open Graph and Twitter card
11+
support.
12+
2. **Sitemap Generation**: A sitemap.xml file is generated after the book is built.
1313
3. **Robots.txt**: A robots.txt file is included to help search engines navigate the site.
14-
15-
4. **Custom CSS/JS**: Custom CSS and JS files are included to improve readability and add structured data for search engines.
14+
4. **Custom CSS/JS**: Custom CSS and JS files are included to improve readability and add structured data for search
15+
engines.
1616

1717
## Building the Book
1818

1919
To build the book with all SEO features:
2020

2121
```bash
22-
# Navigate to the book directory
23-
cd book
24-
25-
# Run the build script
26-
./build_with_sitemap.sh
22+
# Run the Rake task from the project root
23+
rake book:build_with_sitemap
2724
```
2825

2926
This will:
27+
3028
1. Build the book using mdBook
3129
2. Generate the sitemap.xml file
3230
3. Copy the robots.txt file to the output directory
@@ -45,4 +43,4 @@ To customize the SEO settings:
4543
1. Edit `book.toml` to update metadata like title and description
4644
2. Modify `theme/index.hbs` to update meta tags
4745
3. Update `theme/css/custom.css` and `theme/js/custom.js` for styling and behavior
48-
4. Adjust `generate_sitemap.py` to change sitemap generation settings
46+
4. Adjust the sitemap generation settings in `rakelib/book.rake`

book/build_with_sitemap.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.

book/generate_sitemap.py

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
# rb-sys Crate Features
22

3-
The `rb-sys` crate provides battle-tested Rust bindings for the Ruby C API. It uses the [`rust-bindgen`](https://github.com/rust-lang/rust-bindgen) crate to generate bindings from the `ruby.h` header.
3+
The `rb-sys` crate provides battle-tested Rust bindings for the Ruby C API. It uses the
4+
[`rust-bindgen`](https://github.com/rust-lang/rust-bindgen) crate to generate bindings from the `ruby.h` header.
45

56
## Usage Notice
67

7-
This is a very low-level library. If you are looking to write a gem in Rust, you should probably use the [Magnus](https://github.com/matsadler/magnus) crate with the `rb-sys-interop` feature, which provides a higher-level, more ergonomic API.
8+
This is a very low-level library. If you are looking to write a gem in Rust, you should probably use the
9+
[Magnus](https://github.com/matsadler/magnus) crate with the `rb-sys-interop` feature, which provides a higher-level,
10+
more ergonomic API.
811

912
If you need raw/unsafe bindings to libruby, then this crate is for you!
1013

1114
## Writing a Ruby Gem
1215

13-
Ruby gems require boilerplate to be defined to be usable from Ruby. `rb-sys` makes this process painless by doing the work for you. Simply enable the `gem` feature:
16+
Ruby gems require boilerplate to be defined to be usable from Ruby. `rb-sys` makes this process painless by doing the
17+
work for you. Simply enable the `gem` feature:
1418

1519
```toml
1620
[dependencies]
1721
rb-sys = "0.9"
1822
```
1923

20-
Under the hood, this ensures the crate does not link libruby (unless on Windows) and defines a `ruby_abi_version` function for Ruby 3.2+.
24+
Under the hood, this ensures the crate does not link libruby (unless on Windows) and defines a `ruby_abi_version`
25+
function for Ruby 3.2+.
2126

2227
## Embedding libruby in Your Rust App
2328

2429
**IMPORTANT**: If you are authoring a Ruby gem, you do not need to enable this feature.
2530

26-
If you need to link libruby (i.e., you are initializing a Ruby VM in your Rust code), you can enable the `link-ruby` feature:
31+
If you need to link libruby (i.e., you are initializing a Ruby VM in your Rust code), you can enable the `link-ruby`
32+
feature:
2733

2834
```toml
2935
[dependencies]
@@ -45,15 +51,15 @@ Alternatively, you can set the `RUBY_STATIC=true` environment variable.
4551

4652
The `rb-sys` crate provides several features that can be enabled in your `Cargo.toml`:
4753

48-
| Feature | Description |
49-
|---------|-------------|
50-
| `global-allocator` | Report Rust memory allocations to the Ruby GC (_recommended_) |
51-
| `ruby-static` | Link the static version of libruby |
52-
| `link-ruby` | Link libruby (typically used for embedding, not for extensions) |
53-
| `bindgen-rbimpls` | Include the Ruby impl types in bindings |
54-
| `bindgen-deprecated-types` | Include deprecated Ruby methods in bindings |
55-
| `gem` | Set up the crate for use in a Ruby gem (default feature) |
56-
| `stable-api` | Use the stable API (C level) if available for your Ruby version |
54+
| Feature | Description |
55+
| -------------------------- | --------------------------------------------------------------- |
56+
| `global-allocator` | Report Rust memory allocations to the Ruby GC (_recommended_) |
57+
| `ruby-static` | Link the static version of libruby |
58+
| `link-ruby` | Link libruby (typically used for embedding, not for extensions) |
59+
| `bindgen-rbimpls` | Include the Ruby impl types in bindings |
60+
| `bindgen-deprecated-types` | Include deprecated Ruby methods in bindings |
61+
| `gem` | Set up the crate for use in a Ruby gem (default feature) |
62+
| `stable-api` | Use the stable API (C level) if available for your Ruby version |
5763

5864
## Example Cargo.toml
5965

@@ -64,16 +70,18 @@ rb-sys = { version = "0.9", features = ["global-allocator", "stable-api"] }
6470

6571
## Ruby Version Compatibility
6672

67-
`rb-sys` is compatible with Ruby 2.6 and later. The crate detects the Ruby version at compile time and adapts the bindings accordingly.
73+
`rb-sys` is compatible with Ruby 2.6 and later. The crate detects the Ruby version at compile time and adapts the
74+
bindings accordingly.
6875

6976
For Ruby 3.2 and later, `rb-sys` provides a `ruby_abi_version` function that is required for native extensions.
7077

7178
## Integration with Magnus
7279

73-
If you're building a Ruby extension, it's recommended to use the [Magnus](https://github.com/matsadler/magnus) crate on top of `rb-sys`. Magnus provides a high-level, safe API for interacting with Ruby:
80+
If you're building a Ruby extension, it's recommended to use the [Magnus](https://github.com/matsadler/magnus) crate on
81+
top of `rb-sys`. Magnus provides a high-level, safe API for interacting with Ruby:
7482

7583
```toml
7684
[dependencies]
7785
magnus = { version = "0.7", features = ["rb-sys"] }
7886
rb-sys = "0.9"
79-
```
87+
```

book/src/api-reference/rb-sys-gem-config.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# rb_sys Gem Configuration
22

3-
The `rb_sys` gem makes it easy to build native Ruby extensions in Rust. It interoperates with existing Ruby native extension toolchains (i.e., `rake-compiler`) to make testing, building, and cross-compilation of gems easy.
3+
The `rb_sys` gem makes it easy to build native Ruby extensions in Rust. It interoperates with existing Ruby native
4+
extension toolchains (i.e., `rake-compiler`) to make testing, building, and cross-compilation of gems easy.
45

56
## RbSys::ExtensionTask
67

7-
This gem provides a `RbSys::ExtensionTask` class that can be used to build a Ruby extension in Rust. It's a thin wrapper around `Rake::ExtensionTask` that provides sane defaults for building Rust extensions.
8+
This gem provides a `RbSys::ExtensionTask` class that can be used to build a Ruby extension in Rust. It's a thin wrapper
9+
around `Rake::ExtensionTask` that provides sane defaults for building Rust extensions.
810

911
```ruby
1012
# Rakefile
@@ -65,21 +67,25 @@ end
6567

6668
The `rb_sys` gem respects several environment variables that can modify its behavior:
6769

68-
| Environment Variable | Description |
69-
|---------------------|-------------|
70-
| `RB_SYS_CARGO_PROFILE` | Set the Cargo profile (i.e., `release` or `dev`) |
71-
| `RB_SYS_CARGO_FEATURES` | Comma-separated list of Cargo features to enable |
72-
| `RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN` | Force installation of a Rust toolchain |
73-
| `RUBY_STATIC` | Force static linking of libruby if set to `true` |
74-
| `LIBCLANG_PATH` | Path to libclang if it can't be found automatically |
70+
| Environment Variable | Description |
71+
| ------------------------------------- | --------------------------------------------------- |
72+
| `RB_SYS_CARGO_PROFILE` | Set the Cargo profile (i.e., `release` or `dev`) |
73+
| `RB_SYS_CARGO_FEATURES` | Comma-separated list of Cargo features to enable |
74+
| `RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN` | Force installation of a Rust toolchain |
75+
| `RUBY_STATIC` | Force static linking of libruby if set to `true` |
76+
| `LIBCLANG_PATH` | Path to libclang if it can't be found automatically |
7577

7678
## Tips and Tricks
7779

78-
- When using `rake-compiler` to build your gem, you can use the `RB_SYS_CARGO_PROFILE` environment variable to set the Cargo profile (i.e., `release` or `dev`).
80+
- When using `rake-compiler` to build your gem, you can use the `RB_SYS_CARGO_PROFILE` environment variable to set the
81+
Cargo profile (i.e., `release` or `dev`).
7982

8083
- You can pass Cargo arguments to `rake-compiler` like so: `rake compile -- --verbose`
8184

82-
- It's possible to force an installation of a Rust toolchain by setting the `RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN` environment variable. This will install [rustup](https://rustup.rs/) and [cargo](https://crates.io/) in the build directory, so the end user does not have to have Rust pre-installed. Ideally, this should be a last resort, as it's better to already have the toolchain installed on your system.
85+
- It's possible to force an installation of a Rust toolchain by setting the `RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN`
86+
environment variable. This will install [rustup](https://rustup.rs/) and [cargo](https://crates.io/) in the build
87+
directory, so the end user does not have to have Rust pre-installed. Ideally, this should be a last resort, as it's
88+
better to already have the toolchain installed on your system.
8389

8490
## Troubleshooting
8591

@@ -91,9 +97,11 @@ If you see an error like this:
9197
thread 'main' panicked at 'Unable to find libclang: "couldn't find any valid shared libraries matching: \['libclang.so', 'libclang-*.so', 'libclang.so.*', 'libclang-*.so.*'\], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: \[\])"'
9298
```
9399

94-
This means that bindgen is having issues finding a usable version of libclang. An easy way to fix this is to install the [`libclang` gem](https://github.com/oxidize-rb/libclang-rb), which will install a pre-built version of libclang for you. `rb_sys` will automatically detect this gem and use it.
100+
This means that bindgen is having issues finding a usable version of libclang. An easy way to fix this is to install the
101+
[`libclang` gem](https://github.com/oxidize-rb/libclang-rb), which will install a pre-built version of libclang for you.
102+
`rb_sys` will automatically detect this gem and use it.
95103

96104
```ruby
97105
# Gemfile
98106
gem "libclang", "~> 14.0.6"
99-
```
107+
```

0 commit comments

Comments
 (0)