Commit 8fb6dd5b authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

~= improve cross-compile which now works for armv5te

parent dbf86cde
Pipeline #4345 failed with stages
in 2 minutes and 11 seconds
......@@ -20,20 +20,33 @@ set(CMAKE_SYSTEM_PROCESSOR "${PROCESSOR}")
set(CMAKE_C_COMPILER ${TOOLCHAIN_CC})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_CXX})
#set(LIB_DIRS
# "${SYSROOT_PATH}/usr/local/${TOOLCHAIN_HOST}"
# "${SYSROOT_PATH}/usr/local/lib"
#)
#FOREACH(LIB ${LIB_DIRS})
# set(COMMON_FLAGS "${COMMON_FLAGS} -L${LIB} -Wl,-rpath-link,${LIB}")
#ENDFOREACH()
set(INCLUDE_DIRS
"${SYSROOT_PATH}/include"
"${SYSROOT_PATH}/include/bits"
"${SYSROOT_PATH}/include/linux"
"${SYSROOT_PATH}/include/sys"
)
FOREACH(INCL ${INCLUDE_DIRS})
set(COMMON_FLAGS "${COMMON_FLAGS} -I${INCL}")
ENDFOREACH()
set(LIB_DIRS
"${SYSROOT_PATH}/lib"
)
FOREACH(LIB ${LIB_DIRS})
set(COMMON_FLAGS "${COMMON_FLAGS} -L${LIB} -Wl,-rpath-link,${LIB}")
ENDFOREACH()
set(CMAKE_PREFIX_PATH "${SYSROOT_PATH}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${SYSROOT_PATH}/usr/local/${TOOLCHAIN_HOST}/lib")
set(CMAKE_C_FLAGS "${COMMON_FLAGS}" CACHE STRING "Flags")
set(CMAKE_FIND_ROOT_PATH "${CMAKE_INSTALL_PREFIX};${CMAKE_PREFIX_PATH};${CMAKE_SYSROOT}")
message(STATUS "Using prefix path: ${CMAKE_PREFIX_PATH}")
message(STATUS "Using CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
message(STATUS "Using CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
......
......@@ -5,15 +5,8 @@ use std::env;
use std::path::PathBuf;
fn build_cpath(rootfs: String) -> String {
let mut target = env::var("TARGET").unwrap();
if target.eq("armv5te-unknown-linux-musleabi") {
target = "arm-linux-musleabi".to_string();
}
let paths: Vec<String> = vec![
&format!("/usr/local/{}/include", target),
&format!("/usr/local/{}/include/bits", target),
&format!("/usr/local/{}/include/linux", target),
&format!("/usr/local/{}/include/sys", target),
"/include",
]
.into_iter()
.map(|c| format!("{}{}", rootfs, c))
......@@ -22,37 +15,49 @@ fn build_cpath(rootfs: String) -> String {
}
fn main() {
let cross_compile = env::var("TARGET").unwrap() != env::var("HOST").unwrap();
let mut rootfs = "".to_string();
env::set_var("TOOLCHAIN_HOST", "arm-linux-musleabi");
env::set_var("PROCESSOR", "armv5te");
//env::set_var("PATH", path);
env::set_var("ROOTFS", rootfs.clone());
env::set_var("CPATH", build_cpath("".to_string()));
//println!("CPATH: {}", env::var("CPATH").unwrap());
if cross_compile {
let mut target = env::var("TARGET").unwrap();
if target.eq("armv5te-unknown-linux-gnueabi") {
target = "arm-linux-gnueabi".to_string();
}
rootfs = format!("/usr/{}", target);
let cwd = env::current_dir().unwrap();
env::set_var("TOOLCHAIN_HOST", target.clone());
env::set_var("PROCESSOR", "armv5te");
env::set_var("ROOTFS", rootfs.clone());
println!("ROOTFS: {}", env::var("ROOTFS").unwrap());
}
// Tell cargo to invalidate the built crate whenever the wrapper changes
println!("cargo:rerun-if-changed=wrapper.h");
let dst = cmake::Config::new("../")
.build_target("libs")
.always_configure(true)
.define("CMAKE_TOOLCHAIN_FILE", format!("{}/Toolchain.cmake", cwd.display()))
.define("CMAKE_BUILD_TYPE", "RelWithDebInfo")
.build();
let mut target = env::var("TARGET").unwrap();
if target.eq("armv5te-unknown-linux-musleabi") {
target = "arm-linux-musleabi".to_string();
let mut dst = cmake::Config::new("../");
if cross_compile {
let cwd = env::current_dir().unwrap();
dst.define("CMAKE_TOOLCHAIN_FILE", format!("{}/Toolchain.cmake", cwd.display()));
}
println!("cargo:rustc-link-search=all=/usr/local/{}/lib", target);
let dst = dst.build_target("libs")
.always_configure(true)
.define("CMAKE_BUILD_TYPE", "RelWithDebInfo")
.build();
if cross_compile {
env::set_var("CPATH", build_cpath(rootfs.clone()));
let mut target = env::var("TARGET").unwrap();
if target.eq("armv5te-unknown-linux-gnueabi") {
target = "arm-linux-gnueabi".to_string();
}
println!("cargo:rustc-link-search=/usr/{}/lib", target);
}
println!("cargo:rustc-link-search=native={}/build", dst.display());
println!("cargo:rustc-link-lib=dylib=c");
println!("cargo:rustc-link-lib=dylib=prrt");
println!("cargo:rustc-link-lib=dylib=prrtUtil");
let target = env::var("TARGET").unwrap();
// The bindgen::Builder is the main entry point
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment