How do I generate a text file during compile time and include its content in the output?

后端 未结 2 1570
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-13 08:02

I\'m trying to do almost the same as How to create a static string at compile time.

build.rs

use std::{env};
use std::path::Path;
use std::io::{Wri         


        
2条回答
  •  梦毁少年i
    2021-01-13 08:42

    If anyone is interested in a more convenient way to achieve the same, I also created the build_script_file_gen crate which can be used as follows

    build.rs

    extern crate build_script_file_gen;
    use build_script_file_gen::gen_file_str;
    
    fn main() {
        let file_content = "Hello World!";
        gen_file_str("hello.txt", &file_content);
    }
    

    main.rs

    #[macro_use]
    extern crate build_script_file_gen;
    
    fn main() {
        println!(include_file_str!("hello.txt"));
    }
    

提交回复
热议问题