cargo-readme icon indicating copy to clipboard operation
cargo-readme copied to clipboard

build.rs example

Open theduke opened this issue 6 years ago • 2 comments

I like to auto-generate the README with a build.rs build script so I don't forget to update it manually.

The snippet I use:

extern crate cargo_readme;

use std::{fs, path};
use std::io::Write;

fn main() {
    // Generate README.md with cargo_readme.

    let mut f = fs::File::open("src/lib.rs").unwrap();
    let content = cargo_readme::generate_readme(
        &path::PathBuf::from("./"),
        &mut f,
        None,
        false,
        false,
        false,
    ).unwrap();

    let mut f = fs::File::create("README.md").unwrap();
    f.write_all(content.as_bytes()).unwrap();
}

It would be nice to have this snippet in the docs somewhere so you can just copy/paste.

What do you thing, @livioribeiro ?

theduke avatar Sep 16 '17 18:09 theduke

This is quite interesting.

Have this approach slowed down your build times?

I will take a look a this, but if you wish, feel free to open a pull request.

livioribeiro avatar Sep 22 '17 11:09 livioribeiro

FWIW I check this in my travis script. It's not as automated as re-building automatically, but it also only slows down CI, not every build.

quodlibetor avatar Nov 12 '17 20:11 quodlibetor