#build #script #generate #file #include

bin+lib build_script_file_gen

A Rust library which contains convenience methods to generate files with specified content via build scripts and include their content within source files

7 releases (breaking)

0.6.1 Nov 15, 2017
0.6.0 Nov 10, 2017
0.5.0 Nov 10, 2017
0.4.0 Nov 10, 2017
0.1.0 Nov 10, 2017

#74 in Build Utils

Download history 14/week @ 2019-11-27 8/week @ 2019-12-04 79/week @ 2019-12-11 7/week @ 2019-12-25 1/week @ 2020-01-01 28/week @ 2020-01-08 1/week @ 2020-01-22 1/week @ 2020-02-05 7/week @ 2020-02-12 15/week @ 2020-02-19 15/week @ 2020-02-26 16/week @ 2020-03-04 7/week @ 2020-03-11

98 downloads per month

MIT/Apache

7KB

build_script_file_gen

A Rust library which encapsulates convenience methods to generate files via build scripts and include their content within source files during build time.

  1. In build.rs (build script) do,
extern crate build_script_file_gen;
use build_script_file_gen::gen_file_str;

fn main() {
    let string_content = "Hello World!";
    gen_file_str("hello.txt", &string_content);

    //or

    let rust_code = r#"println!("Hello World!");"#;
    gen_file_str("hello.rs", &rust_code);
}
  1. In your module do,
#[macro_use] 
extern crate build_script_file_gen;
 
fn main() {
    //hello.txt contains the text: Hello World!;
    //which will make this function print Hello World! when compiled
    println!(include_file_str!("hello.txt"));

    //or

    //hello.rs contains the text: println!("Hello World!");
    //which will make this function print Hello World! when compiled
    include_file!("hello.rs");
}

lib.rs:

This module encapsulates convenience methods to generate files via build scripts and include their content within source files during build time.

Examples

//Step 1: In build.rs (build script) do,
extern crate build_script_file_gen;
use build_script_file_gen::gen_file_str;

fn main() {
    let string_content = "Hello World!";
    gen_file_str("hello.txt", &string_content);

    //or

    let rust_code = r#"println!("Hello World!");"#;
    gen_file_str("hello.rs", &rust_code);
}
//Step 2: In your module do,
#[macro_use] 
extern crate build_script_file_gen;

fn main() {
    //hello.txt contains the text: Hello World!;
    //which will make this function print Hello World! when compiled
    println!(include_file_str!("hello.txt"));

    //or

    //hello.rs contains the text: println!("Hello World!");
    //which will make this function print Hello World! when compiled
    include_file!("hello.rs");
}

No runtime deps