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

后端 未结 2 1553
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  余生分开走
    2021-01-13 08:37

    The trick was

    concat!(env!("OUT_DIR"), "/file_path.txt")
    

    I changed my main.rs as follows and it worked.

    fn main() {
    
        static LONG_STRING: &'static str = include_str!(concat!(env!("OUT_DIR"), "/file_path.txt"));
    
        println!("{}", LONG_STRING);
    }
    

    The following crates.io documentation helped

    http://doc.crates.io/build-script.html

    https://doc.rust-lang.org/cargo/reference/environment-variables.html

提交回复
热议问题