Skip to content

Commit f419670

Browse files
committed
More doc updates and use clang-cl only with mswin.
1 parent 36acb77 commit f419670

File tree

14 files changed

+109
-94
lines changed

14 files changed

+109
-94
lines changed

docs/cmake/cmake_bindings.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# CMake Bindings
2+
3+
The `CMake` format generates `CMakeLists.txt` and `CMakePresets.json` files for building Rice C++ bindings.
4+
5+
Rice supports building extensions with either [extconf.rb](https://ruby-rice.github.io/4.x/packaging/extconf.rb/) or [CMake](https://ruby-rice.github.io/4.x/packaging/cmake/). While `extconf.rb` works for simple bindings, CMake is vastly superior for anything more complex — it provides better cross-platform support, dependency management, and build configuration.
6+
7+
**Important:** CMake generation must run after Rice generation because it scans the output directory for `*-rb.cpp` files. If no Rice output exists, the generated CMake source lists will be empty.
8+
9+
## Getting Started
10+
11+
See [Getting Started](getting_started.md) for a step-by-step guide.
12+
13+
## Output
14+
15+
See [Output](output.md) for details on the generated files.
16+
17+
## Filtering
18+
19+
See [Filtering](filtering.md) for how to exclude files from the generated CMake build.

docs/cmake/filtering.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Filtering
2+
3+
## Skipping Files
4+
5+
The CMake config supports a `skip` option to exclude specific `*-rb.cpp` files from the generated `CMakeLists.txt`. However, in most cases it's better to add skip patterns to your Rice config instead — that way the problematic files are never generated, and CMake won't find them to include. The CMake `skip` is useful as a quick fix when you have stale generated files on disk that you don't want to recompile.

docs/cmake/getting_started.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Getting Started with CMake Bindings
2+
3+
This guide walks you through generating CMake build files for Rice C++ bindings.
4+
5+
## Prerequisites
6+
7+
You must first generate Rice C++ bindings. See [Getting Started with Rice](../cpp/getting_started.md).
8+
9+
## 1. Create a configuration file
10+
11+
Create a file named `cmake-bindings.yaml`:
12+
13+
```yaml
14+
project: my_extension
15+
output: ./ext/generated
16+
format: CMake
17+
18+
include_dirs:
19+
- "${CMAKE_CURRENT_SOURCE_DIR}/../include"
20+
```
21+
22+
Key options:
23+
24+
- `project` — name used in the CMake `project()` command and build target. When omitted, only subdirectory `CMakeLists.txt` files are generated — useful when you manage the root project files yourself.
25+
- `output` — directory containing the Rice `*-rb.cpp` files. `input` defaults to `output` for CMake.
26+
- `include_dirs` — include directories added via `target_include_directories`. These are CMake expressions written directly into the generated `CMakeLists.txt`.
27+
28+
See [Configuration](../configuration.md) for all options.
29+
30+
## 2. Generate CMake files
31+
32+
Run this **after** generating Rice bindings:
33+
34+
```bash
35+
ruby-bindgen cmake-bindings.yaml
36+
```
37+
38+
## 3. Build
39+
40+
```bash
41+
cd ./ext/generated
42+
cmake --preset linux-debug # or macos-debug, msvc-debug, mingw-debug, etc.
43+
cmake --build build/linux-debug
44+
```
45+
46+
See [Output](output.md) for details on the available presets and generated files.
Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,4 @@
1-
# CMake Bindings
2-
3-
The `CMake` format generates `CMakeLists.txt` and `CMakePresets.json` files for building Rice C++ bindings.
4-
5-
**Important:** CMake generation must run after Rice generation because it scans the output directory for `*-rb.cpp` files. If no Rice output exists, the generated CMake source lists will be empty.
6-
7-
Rice supports building extensions with either [extconf.rb](https://ruby-rice.github.io/4.x/packaging/extconf.rb/) or [CMake](https://ruby-rice.github.io/4.x/packaging/cmake/). While `extconf.rb` works for simple bindings, CMake is vastly superior for anything more complex — it provides better cross-platform support, dependency management, and build configuration.
8-
9-
## Configuration
10-
11-
```yaml
12-
format: CMake
13-
project: my_extension
14-
output: ./ext/generated
15-
# input defaults to output for CMake and scans ./ext/generated for *-rb.cpp
16-
17-
include_dirs:
18-
- "${CMAKE_CURRENT_SOURCE_DIR}/../headers"
19-
```
20-
21-
See [configuration](configuration.md) for details on all options.
22-
23-
## Usage
24-
25-
Generate bindings in two passes:
26-
27-
```bash
28-
# 1. Generate Rice C++ source files
29-
ruby-bindgen rice-bindings.yaml
30-
31-
# 2. Generate CMake build files
32-
ruby-bindgen cmake-bindings.yaml
33-
```
34-
35-
Then build:
36-
37-
```bash
38-
cd /path/to/output
39-
cmake --preset linux-debug # or msvc-debug, macos-debug, etc.
40-
cmake --build build/linux-debug
41-
```
42-
43-
## Skipping Files
44-
45-
The CMake config supports a `skip` option to exclude specific `*-rb.cpp` files from the generated `CMakeLists.txt`. However, in most cases it's better to add skip patterns to your Rice/FFI config instead — that way the problematic files are never generated, and CMake won't find them to include. The CMake `skip` is useful as a quick fix when you have stale generated files on disk that you don't want to recompile.
46-
47-
## Output
1+
# CMake Output
482

493
The CMake format scans the output directory for `*-rb.cpp` files and generates:
504

@@ -65,11 +19,11 @@ flowchart LR
6519
RB --> C1 & C2
6620
```
6721

68-
### Project Files (requires `project`)
22+
## Project Files
6923

7024
When the `project` option is set, `ruby-bindgen` generates the root `CMakeLists.txt` and `CMakePresets.json`. When `project` is omitted, these files are **not** generated — only subdirectory `CMakeLists.txt` files are produced. This is useful when you want to create and manage the root project files yourself and only regenerate subdirectory files on subsequent runs.
7125

72-
### Top Level
26+
## Top-level CMakeLists.txt
7327

7428
The top-level `CMakeLists.txt` is a complete project file that configures the entire build:
7529

@@ -82,6 +36,8 @@ The top-level `CMakeLists.txt` is a complete project file that configures the en
8236

8337
For a well-documented example, see the [BitmapPlusPlus-ruby CMakeLists.txt](https://github.com/ruby-rice/BitmapPlusPlus-ruby/blob/main/ext/CMakeLists.txt). For details on how Rice uses CMake, see the Rice [CMake](https://ruby-rice.github.io/4.x/packaging/cmake/) documentation.
8438

39+
## CMakePresets.json
40+
8541
The top-level directory also gets a `CMakePresets.json` with build presets for all major platforms. For an example, see the [BitmapPlusPlus-ruby CMakePresets.json](https://github.com/ruby-rice/BitmapPlusPlus-ruby/blob/main/ext/CMakePresets.json). For details, see the Rice [CMakePresets.json](https://ruby-rice.github.io/4.x/packaging/cmake/#cmakepresetsjson) documentation.
8642

8743
| Preset | Platform | Compiler |
@@ -94,10 +50,23 @@ The top-level directory also gets a `CMakePresets.json` with build presets for a
9450

9551
All presets use [Ninja](https://ninja-build.org/) as the build generator and include appropriate compiler flags for each platform (visibility settings, debug info, optimization levels).
9652

97-
### Subdirectories
53+
## Subdirectories
9854

9955
Each subdirectory containing `*-rb.cpp` files gets a minimal `CMakeLists.txt` that lists its source files and any nested subdirectories:
10056

57+
```
58+
ext/generated/
59+
CMakeLists.txt # root project (requires project option)
60+
CMakePresets.json # build presets
61+
core/
62+
CMakeLists.txt # add_subdirectory("hal") + target_sources(...)
63+
matrix-rb.cpp
64+
image-rb.cpp
65+
hal/
66+
CMakeLists.txt # target_sources(...)
67+
interface-rb.cpp
68+
```
69+
10170
```cmake
10271
# Subdirectories
10372
add_subdirectory("hal")

docs/configuration.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
ruby-bindgen rice-bindings.yaml
77
```
88

9-
For end-to-end examples, see [C Bindings](c/c_bindings.md), [C++ Bindings](cpp/cpp_bindings.md), and [CMake Bindings](cmake_bindings.md).
9+
For end-to-end examples, see [C Bindings](c/c_bindings.md), [C++ Bindings](cpp/cpp_bindings.md), and [CMake Bindings](cmake/cmake_bindings.md).
1010

1111
## Required Options
1212

@@ -45,7 +45,7 @@ These options apply to all formats.
4545
| Option | Default | Description |
4646
|-----------------|----------------|-------------|
4747
| `project` | none | Project name for the Ruby extension. Used for the `Init_` function name and project wrapper file names. Must be a valid C/C++ identifier. When provided, generates project wrapper files (`{project}-rb.cpp`, `{project}-rb.hpp`). When omitted, only per-file bindings are generated. |
48-
| `include` | auto-generated | Path to a custom Rice include header. See [Include Header](cpp/cpp_bindings.md#include-header). |
48+
| `include` | auto-generated | Path to a custom Rice include header. See [Include Header](cpp/output.md#include-header). |
4949

5050
## CMake Options
5151

@@ -58,8 +58,8 @@ These options apply to all formats.
5858

5959
`ruby-bindgen` uses top-level toolchain keys to configure compiler settings for different platforms:
6060

61-
- **`clang-cl:`** - Used when `RUBY_PLATFORM` contains `mswin` or `mingw`
62-
- **`clang:`** - Used on Linux and macOS
61+
- **`clang-cl:`** - Used when `RUBY_PLATFORM` contains `mswin` (MSVC toolchain)
62+
- **`clang:`** - Used on Linux, macOS, and MinGW
6363

6464
| Option | Default | Description |
6565
|------------|-------------|-------------|
@@ -73,9 +73,9 @@ You only need to include the toolchain sections for platforms you target.
7373
```mermaid
7474
flowchart TD
7575
A["config.yaml location"] --> B["Resolve relative input/output paths"]
76-
B --> C{"RUBY_PLATFORM contains mswin or mingw?"}
76+
B --> C{"RUBY_PLATFORM contains mswin?"}
7777
C -->|Yes| D["Use clang-cl section"]
78-
C -->|No| E["Use clang section"]
78+
C -->|No| E["Use clang section (Linux, macOS, MinGW)"]
7979
D --> F["Set LIBCLANG from toolchain libclang (if provided)"]
8080
E --> F
8181
F --> G["Pass toolchain args to libclang parser"]
@@ -256,7 +256,6 @@ Regex patterns are enclosed in forward slashes (`/pattern/`) and are matched aga
256256
`ruby-bindgen` automatically skips:
257257

258258
- Deprecated functions (marked with `__attribute__((deprecated))`)
259-
- Internal functions (names ending with `_`)
260259
- Methods returning pointers to incomplete types (pimpl pattern)
261260

262261
## Export Macros

docs/cpp/cpp_bindings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ See [Rice Output](output.md) for details on the generated files, including heade
1818

1919
## Build System
2020

21-
After generating Rice bindings, you will need to setup a build system for your extension. `ruby-bindgen` can generate [CMake build files](../cmake_bindings.md) to compile and link the generated bindings.
21+
After generating Rice bindings, you will need to setup a build system for your extension. `ruby-bindgen` can generate [CMake build files](../cmake/cmake_bindings.md) to compile and link the generated bindings.
2222

2323
## Packaging
2424

docs/cpp/getting_started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Then run it **after** the Rice generation:
6363
ruby-bindgen cmake-bindings.yaml
6464
```
6565

66-
See [CMake Bindings](../cmake_bindings.md) for details.
66+
See [CMake Bindings](../cmake/cmake_bindings.md) for details.
6767

6868
## 4. Build the extension
6969

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ flowchart TD
6262
6363
click B "c/c_bindings.md" "C Bindings"
6464
click C "cpp/cpp_bindings.md" "C++ Bindings"
65-
click E "cmake_bindings.md" "CMake Bindings"
65+
click E "cmake/cmake_bindings.md" "CMake Bindings"
6666
click D "https://ruby-rice.github.io/4.x/packaging/extconf/" "Rice extconf.rb packaging"
6767
```
6868

@@ -98,7 +98,7 @@ For much more details, jump to the documentation page for each format:
9898
|-----------|-------------------------------------|
9999
| **FFI** | [C Bindings](c/c_bindings.md) |
100100
| **Rice** | [C++ Bindings](cpp/cpp_bindings.md) |
101-
| **CMake** | [CMake Bindings](cmake_bindings.md) |
101+
| **CMake** | [CMake Bindings](cmake/cmake_bindings.md) |
102102
103103
Finally generate bindings by running the command:
104104

docs/limitations.md

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

docs/prior_art.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This page lists related projects and adjacent tools that influenced, overlap wit
1414

1515
- Project: [ffi_gen](https://github.com/ffi/ffi_gen)
1616
- Scope: Generate Ruby FFI wrappers for C APIs
17-
- Notes: Has not been updated in over a decade and includes liblang findings versus using [ffi-clang](https://github.com/ioquatix/ffi-clang).
17+
- Notes: Has not been updated in over a decade and includes custom libclang bindings versus using [ffi-clang](https://github.com/ioquatix/ffi-clang).
1818

1919
### rbind
2020

0 commit comments

Comments
 (0)