From cf8f8ebdb2240b7e89b9adc835b92410682f5dfa Mon Sep 17 00:00:00 2001 From: David Goodlad Date: Wed, 24 Apr 2019 09:26:47 +1000 Subject: [PATCH] Include all the SDK static archives directly This avoids all sorts of complex linking activity downstream --- Cargo.toml | 2 ++ build.rs | 53 ++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9a0b512..8cf9b4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,9 +6,11 @@ edition = "2018" links = "sdk" [dependencies] +freertos_rs = { git = "https://github.com/hashmismatch/freertos.rs", rev = "a5b296a64d48db97c711673a825f6a0e5b9d9188" } cty = "0.2" [build-dependencies] cc = { version = "1.0", features = ["parallel"] } bindgen = "0.49.0" llvm-tools = "0.1.1" +glob = "0.3.0" diff --git a/build.rs b/build.rs index 24010f9..00887fd 100644 --- a/build.rs +++ b/build.rs @@ -1,13 +1,16 @@ extern crate bindgen; extern crate cc; +extern crate glob; extern crate llvm_tools; +use glob::glob; +use llvm_tools::LlvmTools; use std::env; +use std::fmt; +use std::fs; use std::path::PathBuf; use std::process::Command; -use llvm_tools::LlvmTools; - const STDLIB_INCLUDE_PATHS: &[&'static str] = &[ "/usr/lib/gcc/arm-none-eabi/5.4.1/include", "/usr/lib/gcc/arm-none-eabi/5.4.1/include-fixed", @@ -239,8 +242,21 @@ const SDK_C_FILES: &[&'static str] = &[ "vendor/sdk/component/common/utilities/xml.c", ]; +const SDK_STATIC_LIBS: &[&'static str] = &[ + "platform", + "wlan", + "http", + "dct", + "wps", + "rtlstd", + "websocket", + "xmodem", + "mdns" +]; + fn main() { let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + let sdk_staticlib_path = PathBuf::from("vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC").canonicalize().unwrap(); let tools = LlvmTools::new().unwrap(); let objcopy = match tools.tool("llvm-objcopy") { @@ -248,6 +264,23 @@ fn main() { None => panic!("Couldn't find objcopy"), }; + for lib_name in SDK_STATIC_LIBS.iter() { + fs::create_dir_all(out_path.join("static").join(lib_name)).expect("Could not create directory"); + + Command::new("ar") + .arg("x") + .arg(sdk_staticlib_path.join(format!("lib_{}.a", lib_name)).to_str().unwrap()) + .current_dir(out_path.join("static").join(lib_name)) + .status().unwrap(); + } + + let sdk_static_lib_object_paths = glob(out_path.join("static/**/*.o").to_str().unwrap()).unwrap().into_iter().filter_map(|entry| { + match entry { + Ok(path) => Some(path), + Err(_) => None, + } + }).collect::>(); + Command::new(objcopy) .args(&["--rename-section", ".data=.loader.data,contents,alloc,load,readonly,data"]) .args(&["-I", "binary"]) @@ -287,23 +320,17 @@ fn main() { compiler.include(path); } + for path in sdk_static_lib_object_paths { + compiler.object(path); + } + compiler .object(out_path.join("ram_1.r.o")) + .object("vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_wlan.a") .files(SDK_C_FILES) .file("src/freertos_rs.c") .compile("sdk"); - println!("cargo:rustc-link-search=native=vendor/sdk/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/"); - println!("cargo:rustc-link-lib=_platform"); - println!("cargo:rustc-link-lib=_wlan"); - println!("cargo:rustc-link-lib=_http"); - println!("cargo:rustc-link-lib=_dct"); - println!("cargo:rustc-link-lib=_wps"); - println!("cargo:rustc-link-lib=_rtlstd"); - println!("cargo:rustc-link-lib=_websocket"); - println!("cargo:rustc-link-lib=_xmodem"); - println!("cargo:rustc-link-lib=_mdns"); - let bindings = bindgen::Builder::default() .header("include/wrapper.h") .whitelist_function("wifi_manager_init")