1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::env;
use std::path::Path;
fn main() {
let llvm_path =
env::var("MU_LLVM_PATH").unwrap_or("/usr/local/mu_library/mu_llvm/llvm-18.1".to_string());
println!("cargo:rerun-if-changed=src");
let linker_path = format!("{}/bin/ld.lld", llvm_path);
println!("cargo:rustc-linker={}", linker_path);
// Set linker script path
let picolibc_newlib_path = format!("{}/picolibc-rv/newlib", llvm_path);
println!("cargo:rustc-link-search={}", picolibc_newlib_path);
let builtins_rv_path = format!("{}/builtins-rv", llvm_path);
println!("cargo:rustc-link-search={}", builtins_rv_path);
println!("cargo:rustc-link-lib=clang_rt.builtins-riscv64");
let mu_lib_path = env::var("MU_LIB_PATH").unwrap_or("/usr/local/mu_library/mu".to_string());
// Link mu_std library
let mu_lib_dir = Path::new(&mu_lib_path).join("lib");
println!("cargo:rustc-link-search={}", mu_lib_dir.display());
println!("cargo:rustc-link-lib=mu_std");
// Set target-feature
println!("cargo:rustc-flag=-C target-feature=+xmetis");
if std::env::var("DOCS_RS").is_ok() {
// skip bindgen for docs.rs
return;
}
/* NOTE: Activate only when generating new bindings.
* We primarily provide bindings,
* so there's no need to generate bindings on every build.
* However, if you want to generate new bindings, you can enable this code.
* You need to provide MU_RB_HPP_PATH when you enable this code.
*/
// let mu_rb_hpp_path = env::var("MU_RB_HPP_PATH")
// .unwrap_or("/usr/local/mu_library/mu/include/mu/mu_rb.hpp".to_string());
// println!("cargo:rerun-if-changed={}", mu_rb_hpp_path);
// let bindings = bindgen::Builder::default()
// .enable_cxx_namespaces()
// .header(mu_rb_hpp_path)
// .clang_arg(format!("-I{}/picolibc-rv/include", llvm_path)) // stdint.h
// .clang_arg(format!("-I{}/libcxx-rv/include/c++/v1", llvm_path)) // cstdint
// .clang_arg(format!("-I{}/include", mu_lib_path))
// .parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// .generate()
// .expect("Unable to generate bindings");
// bindings
// .write_to_file("src/bindings.rs")
// .expect("Couldn't write bindings!");
}