Skip to content

Commit 2b33682

Browse files
authored
Autogenerate README based on library documentation with cargo-readme (#23)
As discussed just last week it's annoying to keep the README and library docs in sync, in particular because the code in `README.md` isn't build-tested like the module docs. Fortunately `cargo-readme` feeds two birds with one scone: it bases (part of) `README.md` on the module documentation - which was tested with `cargo test` just prior.
1 parent 0ecd805 commit 2b33682

File tree

4 files changed

+82
-12
lines changed

4 files changed

+82
-12
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,29 @@ jobs:
7070
with:
7171
command: clippy
7272
args: --workspace --all-targets --all-features -- -D warnings
73+
74+
doc:
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v2
78+
- uses: actions-rs/toolchain@v1
79+
with:
80+
profile: minimal
81+
toolchain: stable
82+
override: true
83+
- name: Use cached cargo-readme
84+
uses: actions/cache@v2
85+
id: cargo-readme-cache
86+
with:
87+
path: ~/.cargo/bin/cargo-readme
88+
key: ${{ runner.os }}-cargo-readme
89+
- name: Install cargo-readme
90+
if: steps.cargo-readme-cache.outputs.cache-hit != 'true'
91+
uses: actions-rs/cargo@v1
92+
with:
93+
command: install
94+
args: cargo-readme
95+
- name: Check if README.md is up-to-date
96+
run: |
97+
cargo readme > README.md
98+
git diff --quiet || (echo '::error::Generated README is different, please regenerate with `cargo readme > README.md`'; git diff; false)

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# 📒 gpu-allocator
1+
📒 gpu-allocator
2+
=
23

34
[![Actions Status](https://github.com/Traverse-Research/gpu-allocator/workflows/CI/badge.svg)](https://github.com/Traverse-Research/gpu-allocator/actions)
5+
[![Latest version](https://img.shields.io/crates/v/gpu-allocator.svg)](https://crates.io/crates/gpu-allocator)
46
[![Docs](https://docs.rs/gpu-allocator/badge.svg)](https://docs.rs/gpu-allocator/)
57
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE-MIT)
68
[![LICENSE](https://img.shields.io/badge/license-apache-blue.svg)](LICENSE-APACHE)
79
[![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v1.4%20adopted-ff69b4.svg)](../main/CODE_OF_CONDUCT.md)
8-
[![Latest version](https://img.shields.io/crates/v/gpu-allocator.svg)](https://crates.io/crates/gpu-allocator)
910

1011
[![Banner](banner.png)](https://traverseresearch.nl)
1112

@@ -14,10 +15,12 @@
1415
gpu-allocator = "0.6.0"
1516
```
1617

17-
## Setting up the allocator for Vulkan
18+
This crate provides a fully written in Rust memory allocator for Vulkan, and will provide one for DirectX 12 in the future.
19+
20+
### Setting up the Vulkan memory allocator
21+
1822
```rust
19-
use ash::version::{DeviceV1_0, EntryV1_0, InstanceV1_0};
20-
use ash::vk;
23+
use gpu_allocator::*;
2124

2225
let mut allocator = VulkanAllocator::new(&VulkanAllocatorCreateDesc {
2326
instance,
@@ -27,30 +30,33 @@ let mut allocator = VulkanAllocator::new(&VulkanAllocatorCreateDesc {
2730
});
2831
```
2932

30-
## Vulkan allocation example
33+
### Simple Vulkan allocation example
34+
3135
```rust
36+
use gpu_allocator::*;
37+
38+
3239
// Setup vulkan info
3340
let vk_info = vk::BufferCreateInfo::builder()
3441
.size(512)
3542
.usage(vk::BufferUsageFlags::STORAGE_BUFFER);
3643

37-
let buffer = unsafe { device.create_buffer(&vk_info, None) }?;
44+
let buffer = unsafe { device.create_buffer(&vk_info, None) }.unwrap();
3845
let requirements = unsafe { device.get_buffer_memory_requirements(buffer) };
3946

40-
4147
let allocation = allocator
4248
.allocate(&AllocationCreateDesc {
4349
name: "Example allocation",
4450
requirements,
4551
location: MemoryLocation::CpuToGpu,
4652
linear: true, // Buffers are always linear
47-
})?;
53+
}).unwrap();
4854

4955
// Bind memory to the buffer
50-
unsafe { device.bind_buffer_memory(buffer, allocation.memory(), allocation.offset())? };
56+
unsafe { device.bind_buffer_memory(buffer, allocation.memory(), allocation.offset()).unwrap() };
5157

5258
// Cleanup
53-
allocator.free(allocation)?;
59+
allocator.free(allocation).unwrap();
5460
unsafe { device.destroy_buffer(buffer, None) };
5561
```
5662

README.tpl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
📒 {{crate}}
2+
=
3+
4+
[![Actions Status](https://github.com/Traverse-Research/gpu-allocator/workflows/CI/badge.svg)](https://github.com/Traverse-Research/gpu-allocator/actions)
5+
[![Latest version](https://img.shields.io/crates/v/gpu-allocator.svg)](https://crates.io/crates/gpu-allocator)
6+
[![Docs](https://docs.rs/gpu-allocator/badge.svg)](https://docs.rs/gpu-allocator/)
7+
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE-MIT)
8+
[![LICENSE](https://img.shields.io/badge/license-apache-blue.svg)](LICENSE-APACHE)
9+
[![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v1.4%20adopted-ff69b4.svg)](../main/CODE_OF_CONDUCT.md)
10+
11+
[![Banner](banner.png)](https://traverseresearch.nl)
12+
13+
```toml
14+
[dependencies]
15+
gpu-allocator = "0.6.0"
16+
```
17+
18+
{{readme}}
19+
20+
### License
21+
22+
Licensed under either of
23+
24+
* Apache License, Version 2.0, ([LICENSE-APACHE](../master/LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
25+
* MIT license ([LICENSE-MIT](../master/LICENSE-MIT) or http://opensource.org/licenses/MIT)
26+
27+
at your option.
28+
29+
### Alternative libraries
30+
* [vk-mem-rs](https://github.com/gwihlidal/vk-mem-rs)
31+
32+
### Contribution
33+
34+
Unless you explicitly state otherwise, any contribution intentionally
35+
submitted for inclusion in the work by you, as defined in the Apache-2.0
36+
license, shall be dual licensed as above, without any additional terms or
37+
conditions.

release.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ sign-tag = true
77

88
pre-release-replacements = [
99
{file="README.md", search="gpu-allocator = .*", replace="{{crate_name}} = \"{{version}}\""},
10-
]
10+
{file="README.tpl", search="gpu-allocator = .*", replace="{{crate_name}} = \"{{version}}\""},
11+
]

0 commit comments

Comments
 (0)