Sha256: 10d74a7160e3651f9dc2c9a1aa07fb419b9c870bc76d23aebc19489aa65be7f0

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

use std::{
    env,
    error::Error,
    fs::{create_dir_all, File},
    io::{Read, Write},
    path::PathBuf,
};

fn main() -> Result<(), Box<dyn Error>> {
    // Propogate linking from rb-sys for usage in the wasmtime-rb Rust crate
    let _ = rb_sys_env::activate()?;

    bundle_ruby_file("lib/wasmtime/error.rb")?;
    bundle_ruby_file("lib/wasmtime/component.rb")?;

    Ok(())
}

fn bundle_ruby_file(filename: &str) -> Result<(), Box<dyn Error>> {
    let out_dir = PathBuf::from(env::var("OUT_DIR")?).join("bundled");
    let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
    let file = manifest_dir.join("..").join(filename);
    println!("cargo:rerun-if-changed={}", file.display());
    let out_path = file.file_name().unwrap();
    let out_path = out_path.to_string_lossy().replace(".rb", ".rs");
    let out_path = out_dir.join(out_path);
    create_dir_all(out_dir)?;
    let mut out = File::create(out_path)?;

    let contents = {
        let mut file = File::open(file)?;
        let mut contents = String::new();
        file.read_to_string(&mut contents)?;
        contents
    };

    let template = r##"
// This file is generated by build.rs

use magnus::eval;

pub fn init() -> Result<(), magnus::Error> {
    let _: magnus::Value = eval!(
        r#"
__FILE_CONTENTS__
    "#
    )?;

    Ok(())
}

"##;

    let contents = template.replace("__FILE_CONTENTS__", &contents);

    out.write_all(contents.as_bytes())?;

    Ok(())
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ext/build.rs
wasmtime-28.0.0 ext/build.rs
wasmtime-27.0.0 ext/build.rs