From 2ba4d8935db9dee33913352beafe65c4fdec0a7b Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 25 Jun 2021 15:57:39 +0800 Subject: [PATCH] fix compilation with nixpkgs 21.05 The environment variable is optional to keep compatibility with other build environments. Closes #131 --- default.nix | 1 + shell.nix | 1 + src/libc/build.rs | 5 +++++ src/libunwind/build.rs | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/default.nix b/default.nix index ca65887..861d093 100644 --- a/default.nix +++ b/default.nix @@ -31,6 +31,7 @@ let ]; buildPhase = '' export XARGO_RUST_SRC="${rustPlatform.rust.rustc}/lib/rustlib/src/rust/library" + export CLANG_EXTRA_INCLUDE_DIR="${pkgs.llvmPackages_9.clang-unwrapped.lib}/lib/clang/9.0.1/include" export CARGO_HOME=$(mktemp -d cargo-home.XXX) make TARGET=${target} GWARGS="${if json == null then "-V ${variant}" else json}" ''; diff --git a/shell.nix b/shell.nix index cb800cc..c3221d9 100644 --- a/shell.nix +++ b/shell.nix @@ -30,6 +30,7 @@ in ]; XARGO_RUST_SRC = "${rustPlatform.rust.rustc}/lib/rustlib/src/rust/library"; + CLANG_EXTRA_INCLUDE_DIR = "${pkgs.llvmPackages_9.clang-unwrapped.lib}/lib/clang/9.0.1/include"; OPENOCD_ZYNQ = "${zynq-rs}/openocd"; SZL = "${zc706-szl}/szl.elf"; } diff --git a/src/libc/build.rs b/src/libc/build.rs index 43ab8e6..08002d9 100644 --- a/src/libc/build.rs +++ b/src/libc/build.rs @@ -5,6 +5,8 @@ fn main() { mod libc { use std::path::Path; + use std::env; + pub fn compile() { let cfg = &mut cc::Build::new(); cfg.no_default_flags(true); @@ -16,6 +18,9 @@ mod libc { cfg.flag("-ffreestanding"); cfg.flag("-fno-PIC"); cfg.flag("-isystem../include"); + if let Ok(extra_include) = env::var("CLANG_EXTRA_INCLUDE_DIR") { + cfg.flag(&("-isystem".to_owned() + &extra_include)); + } cfg.flag("-fno-stack-protector"); cfg.flag("--target=armv7-none-eabihf"); cfg.flag("-O2"); diff --git a/src/libunwind/build.rs b/src/libunwind/build.rs index d7f6645..51dc16c 100644 --- a/src/libunwind/build.rs +++ b/src/libunwind/build.rs @@ -6,6 +6,7 @@ fn main() { mod llvm_libunwind { use std::path::Path; + use std::env; fn setup_options(cfg: &mut cc::Build) { cfg.no_default_flags(true); @@ -16,6 +17,9 @@ mod llvm_libunwind { cfg.flag("-fno-PIC"); cfg.flag("-Isrc"); cfg.flag("-isystem../include"); + if let Ok(extra_include) = env::var("CLANG_EXTRA_INCLUDE_DIR") { + cfg.flag(&("-isystem".to_owned() + &extra_include)); + } cfg.flag("-fno-stack-protector"); cfg.flag("--target=armv7-none-eabihf"); cfg.flag("-O2");