forked from M-Labs/artiq-zynq
cc: fixed error and compiled unlzma using cc
This commit is contained in:
parent
b0aa77c73f
commit
214337387f
|
@ -430,6 +430,7 @@ dependencies = [
|
||||||
name = "szl"
|
name = "szl"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"cc",
|
||||||
"cstr_core",
|
"cstr_core",
|
||||||
"libboard_zynq",
|
"libboard_zynq",
|
||||||
"libcortex_a9",
|
"libcortex_a9",
|
||||||
|
|
|
@ -7,16 +7,18 @@ mod libc {
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
pub fn compile() {
|
pub fn compile() {
|
||||||
let cfg = &mut cc::Build::new();
|
let cfg = &mut cc::Build::new();
|
||||||
|
cfg.no_default_flags(true);
|
||||||
|
cfg.compiler("clang");
|
||||||
cfg.cpp(false);
|
cfg.cpp(false);
|
||||||
cfg.warnings(false);
|
cfg.warnings(false);
|
||||||
|
|
||||||
// still have problem compiling the libunwind
|
|
||||||
cfg.flag("-nostdlib");
|
cfg.flag("-nostdlib");
|
||||||
cfg.flag("-ffreestanding");
|
cfg.flag("-ffreestanding");
|
||||||
cfg.flag("-fno-PIC");
|
cfg.flag("-fno-PIC");
|
||||||
cfg.flag("-isystem../include");
|
cfg.flag("-isystem../include");
|
||||||
cfg.flag("-fno-stack-protector");
|
cfg.flag("-fno-stack-protector");
|
||||||
cfg.flag("--target=armv7-none-eabihf");
|
cfg.flag("--target=armv7-none-eabihf");
|
||||||
|
cfg.flag("-O2");
|
||||||
|
|
||||||
cfg.flag("-std=c99");
|
cfg.flag("-std=c99");
|
||||||
cfg.flag("-fstrict-aliasing");
|
cfg.flag("-fstrict-aliasing");
|
||||||
|
@ -25,12 +27,12 @@ mod libc {
|
||||||
cfg.flag("-U_FORTIFY_SOURCE");
|
cfg.flag("-U_FORTIFY_SOURCE");
|
||||||
cfg.define("_FORTIFY_SOURCE", Some("0"));
|
cfg.define("_FORTIFY_SOURCE", Some("0"));
|
||||||
|
|
||||||
let unwind_sources = vec![
|
let sources = vec![
|
||||||
"printf.c"
|
"printf.c"
|
||||||
];
|
];
|
||||||
|
|
||||||
let root = Path::new("../libc");
|
let root = Path::new("./");
|
||||||
for src in unwind_sources {
|
for src in sources {
|
||||||
println!("cargo:rerun-if-changed={}", src);
|
println!("cargo:rerun-if-changed={}", src);
|
||||||
cfg.file(root.join("src").join(src));
|
cfg.file(root.join("src").join(src));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,16 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
llvm_libunwind::compile();
|
llvm_libunwind::compile_cpp();
|
||||||
|
llvm_libunwind::compile_c();
|
||||||
}
|
}
|
||||||
|
|
||||||
mod llvm_libunwind {
|
mod llvm_libunwind {
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
/// Compile the libunwind C/C++ source code.
|
fn setup_options(cfg: &mut cc::Build) {
|
||||||
pub fn compile() {
|
cfg.no_default_flags(true);
|
||||||
let cfg = &mut cc::Build::new();
|
|
||||||
cfg.cpp(true);
|
|
||||||
cfg.cpp_set_stdlib(None);
|
|
||||||
cfg.warnings(false);
|
cfg.warnings(false);
|
||||||
|
|
||||||
// libunwind expects a __LITTLE_ENDIAN__ macro to be set for LE archs, cf. #65765
|
|
||||||
cfg.define("__LITTLE_ENDIAN__", Some("1"));
|
|
||||||
// still have problem compiling the libunwind
|
|
||||||
cfg.flag("-nostdlib");
|
cfg.flag("-nostdlib");
|
||||||
cfg.flag("-ffreestanding");
|
cfg.flag("-ffreestanding");
|
||||||
cfg.flag("-fno-PIC");
|
cfg.flag("-fno-PIC");
|
||||||
|
@ -23,12 +18,55 @@ mod llvm_libunwind {
|
||||||
cfg.flag("-isystem../include");
|
cfg.flag("-isystem../include");
|
||||||
cfg.flag("-fno-stack-protector");
|
cfg.flag("-fno-stack-protector");
|
||||||
cfg.flag("--target=armv7-none-eabihf");
|
cfg.flag("--target=armv7-none-eabihf");
|
||||||
|
cfg.flag("-O2");
|
||||||
|
|
||||||
|
cfg.flag("-std=c99");
|
||||||
|
cfg.flag("-fstrict-aliasing");
|
||||||
|
cfg.flag("-fvisibility=hidden");
|
||||||
|
cfg.flag_if_supported("-fvisibility-global-new-delete-hidden");
|
||||||
cfg.define("_LIBUNWIND_IS_BAREMETAL", Some("1"));
|
cfg.define("_LIBUNWIND_IS_BAREMETAL", Some("1"));
|
||||||
cfg.define("_LIBUNWIND_NO_HEAP", Some("1"));
|
cfg.define("_LIBUNWIND_NO_HEAP", Some("1"));
|
||||||
cfg.define("_LIBUNWIND_HAS_NO_THREADS", Some("1"));
|
cfg.define("_LIBUNWIND_HAS_NO_THREADS", Some("1"));
|
||||||
cfg.define("NDEBUG", Some("1"));
|
cfg.define("NDEBUG", Some("1"));
|
||||||
|
// libunwind expects a __LITTLE_ENDIAN__ macro to be set for LE archs, cf. #65765
|
||||||
|
cfg.define("__LITTLE_ENDIAN__", Some("1"));
|
||||||
|
cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None);
|
||||||
|
cfg.flag("-U_FORTIFY_SOURCE");
|
||||||
|
cfg.define("_FORTIFY_SOURCE", Some("0"));
|
||||||
|
}
|
||||||
|
|
||||||
cfg.flag("-std=c99");
|
pub fn compile_c() {
|
||||||
|
let cfg = &mut cc::Build::new();
|
||||||
|
setup_options(cfg);
|
||||||
|
cfg.compiler("clang");
|
||||||
|
|
||||||
|
let unwind_sources = vec![
|
||||||
|
"Unwind-sjlj.c",
|
||||||
|
"UnwindLevel1-gcc-ext.c",
|
||||||
|
"UnwindLevel1.c",
|
||||||
|
"UnwindRegistersRestore.S",
|
||||||
|
"UnwindRegistersSave.S",
|
||||||
|
];
|
||||||
|
|
||||||
|
let root = Path::new("../llvm_libunwind");
|
||||||
|
cfg.include(root.join("include"));
|
||||||
|
for src in unwind_sources {
|
||||||
|
println!("cargo:rerun-if-changed={}", src);
|
||||||
|
cfg.file(root.join("src").join(src));
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.compile("unwind_c");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Compile the libunwind C/C++ source code.
|
||||||
|
pub fn compile_cpp() {
|
||||||
|
let cfg = &mut cc::Build::new();
|
||||||
|
setup_options(cfg);
|
||||||
|
cfg.compiler("clang++");
|
||||||
|
cfg.cpp(true);
|
||||||
|
cfg.cpp_set_stdlib(None);
|
||||||
|
|
||||||
|
// c++ options
|
||||||
cfg.flag("-std=c++11");
|
cfg.flag("-std=c++11");
|
||||||
cfg.flag("-nostdinc++");
|
cfg.flag("-nostdinc++");
|
||||||
cfg.flag("-fno-exceptions");
|
cfg.flag("-fno-exceptions");
|
||||||
|
@ -37,18 +75,10 @@ mod llvm_libunwind {
|
||||||
cfg.flag("-funwind-tables");
|
cfg.flag("-funwind-tables");
|
||||||
cfg.flag("-fvisibility=hidden");
|
cfg.flag("-fvisibility=hidden");
|
||||||
cfg.flag_if_supported("-fvisibility-global-new-delete-hidden");
|
cfg.flag_if_supported("-fvisibility-global-new-delete-hidden");
|
||||||
cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None);
|
|
||||||
cfg.flag("-U_FORTIFY_SOURCE");
|
|
||||||
cfg.define("_FORTIFY_SOURCE", Some("0"));
|
|
||||||
|
|
||||||
let unwind_sources = vec![
|
let unwind_sources = vec![
|
||||||
"Unwind-EHABI.cpp",
|
"Unwind-EHABI.cpp",
|
||||||
"Unwind-seh.cpp",
|
"Unwind-seh.cpp",
|
||||||
"Unwind-sjlj.c",
|
|
||||||
"UnwindLevel1-gcc-ext.c",
|
|
||||||
"UnwindLevel1.c",
|
|
||||||
"UnwindRegistersRestore.S",
|
|
||||||
"UnwindRegistersSave.S",
|
|
||||||
"libunwind.cpp"
|
"libunwind.cpp"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -59,6 +89,6 @@ mod llvm_libunwind {
|
||||||
cfg.file(root.join("src").join(src));
|
cfg.file(root.join("src").join(src));
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.compile("unwind");
|
cfg.compile("unwind_cpp");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,3 +15,6 @@ cstr_core = { version = "0.2", default-features = false }
|
||||||
libboard_zynq = { git = "https://git.m-labs.hk/M-Labs/zc706.git" }
|
libboard_zynq = { git = "https://git.m-labs.hk/M-Labs/zc706.git" }
|
||||||
libsupport_zynq = { git = "https://git.m-labs.hk/M-Labs/zc706.git" }
|
libsupport_zynq = { git = "https://git.m-labs.hk/M-Labs/zc706.git" }
|
||||||
libcortex_a9 = { git = "https://git.m-labs.hk/M-Labs/zc706.git" }
|
libcortex_a9 = { git = "https://git.m-labs.hk/M-Labs/zc706.git" }
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
cc = { version = "1.0.1" }
|
||||||
|
|
|
@ -1,28 +1,14 @@
|
||||||
use std::process::Command;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
let out = env::var("OUT_DIR").unwrap();
|
let out = env::var("OUT_DIR").unwrap();
|
||||||
let out_dir = &PathBuf::from(&out);
|
let out_dir = &PathBuf::from(&out);
|
||||||
|
|
||||||
let status = Command::new("clang")
|
compile_unlzma();
|
||||||
.args(&["-target", "armv7-unknown-linux", "-fno-stack-protector",
|
|
||||||
"src/unlzma.c", "-O2", "-c", "-fPIC", "-o",
|
|
||||||
&format!("{}/unlzma.o", out)])
|
|
||||||
.status().unwrap();
|
|
||||||
assert!(status.success());
|
|
||||||
let status = Command::new("llvm-ar")
|
|
||||||
.args(&["crus", "libunlzma.a", "unlzma.o"])
|
|
||||||
.current_dir(&Path::new(&out))
|
|
||||||
.status().unwrap();
|
|
||||||
assert!(status.success());
|
|
||||||
println!("cargo:rustc-link-search=native={}", out);
|
|
||||||
println!("cargo:rustc-link-lib=static=unlzma");
|
|
||||||
println!("cargo:rerun-if-changed=src/unlzma.c");
|
|
||||||
|
|
||||||
// Put the linker script somewhere the linker can find it
|
// Put the linker script somewhere the linker can find it
|
||||||
File::create(out_dir.join("link.x"))
|
File::create(out_dir.join("link.x"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -34,3 +20,29 @@ fn main() {
|
||||||
// instead of when any part of the source code changes.
|
// instead of when any part of the source code changes.
|
||||||
println!("cargo:rerun-if-changed=link.x");
|
println!("cargo:rerun-if-changed=link.x");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn compile_unlzma() {
|
||||||
|
let cfg = &mut cc::Build::new();
|
||||||
|
cfg.compiler("clang");
|
||||||
|
cfg.no_default_flags(true);
|
||||||
|
cfg.warnings(false);
|
||||||
|
|
||||||
|
cfg.flag("-nostdlib");
|
||||||
|
cfg.flag("-ffreestanding");
|
||||||
|
cfg.flag("-fPIC");
|
||||||
|
cfg.flag("-fno-stack-protector");
|
||||||
|
cfg.flag("--target=armv7-unknown-linux");
|
||||||
|
cfg.flag("-O2");
|
||||||
|
|
||||||
|
let sources = vec![
|
||||||
|
"unlzma.c",
|
||||||
|
];
|
||||||
|
|
||||||
|
let root = Path::new("./");
|
||||||
|
for src in sources {
|
||||||
|
println!("cargo:rerun-if-changed={}", src);
|
||||||
|
cfg.file(root.join("src").join(src));
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.compile("unlzma");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue