forked from M-Labs/artiq
1
0
Fork 0

firmware: apply build flags globally, move --cfg handling to build.rs.

This commit is contained in:
whitequark 2017-01-03 20:12:56 +00:00
parent 9a80b8d533
commit c2d86c4f67
4 changed files with 43 additions and 24 deletions

View File

@ -2,6 +2,7 @@
authors = ["M-Labs"] authors = ["M-Labs"]
name = "ksupport" name = "ksupport"
version = "0.0.0" version = "0.0.0"
build = "build.rs"
[lib] [lib]
name = "ksupport" name = "ksupport"

View File

@ -0,0 +1,17 @@
use std::env;
use std::path::Path;
use std::io::{BufRead, BufReader};
use std::fs::File;
fn main() {
let out_dir = env::var("BUILDINC_DIRECTORY").unwrap();
let cfg_path = Path::new(&out_dir).join("generated").join("rust-cfg");
println!("cargo:rerun-if-changed={}", cfg_path.to_str().unwrap());
let f = BufReader::new(File::open(&cfg_path).unwrap());
for line in f.lines() {
println!("cargo:rustc-cfg={}", line.unwrap());
}
println!("cargo:rustc-cfg={}", "ksupport");
}

View File

@ -2,13 +2,22 @@ extern crate walkdir;
use std::env; use std::env;
use std::fs::File; use std::fs::File;
use std::io::Write; use std::io::{Write, BufRead, BufReader};
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
use walkdir::WalkDir; use walkdir::WalkDir;
fn main() { fn main() {
let out_dir = env::var("BUILDINC_DIRECTORY").unwrap();
let cfg_path = Path::new(&out_dir).join("generated").join("rust-cfg");
println!("cargo:rerun-if-changed={}", cfg_path.to_str().unwrap());
let f = BufReader::new(File::open(&cfg_path).unwrap());
for line in f.lines() {
println!("cargo:rustc-cfg={}", line.unwrap());
}
let out_dir = env::var("OUT_DIR").unwrap(); let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("git_info.rs"); let dest_path = Path::new(&out_dir).join("git_info.rs");
let mut f = File::create(&dest_path).unwrap(); let mut f = File::create(&dest_path).unwrap();

View File

@ -6,9 +6,8 @@ PYTHON ?= python3.5
OBJECTS := flash_storage.o main.o OBJECTS := flash_storage.o main.o
OBJECTS_KSUPPORT := ksupport_glue.o artiq_personality.o OBJECTS_KSUPPORT := ksupport_glue.o artiq_personality.o
RUSTOUT_DIRECTORY := cargo/or1k-unknown-none/debug RUSTOUT := cargo/or1k-unknown-none/debug
CORE_IO_COMMIT := d40c593f42fafbac1ff3d827f6df96338b5b7d8b RUSTOUT_KSUPPORT := cargo-ksupport/or1k-unknown-none/debug
export CORE_IO_COMMIT
CFLAGS += \ CFLAGS += \
-I$(LIBALLOC_DIRECTORY) \ -I$(LIBALLOC_DIRECTORY) \
@ -31,17 +30,14 @@ LDFLAGS += --gc-sections \
all: runtime.bin runtime.fbi all: runtime.bin runtime.fbi
.PHONY: $(RUSTOUT_DIRECTORY)/libruntime.a .PHONY: $(RUSTOUT)/libruntime.a
$(RUSTOUT_DIRECTORY)/libruntime.a: ksupport.elf $(RUSTOUT)/libruntime.a: ksupport.elf
RUSTFLAGS="-C target-feature=+mul,+div,+ffl1,+cmov,+addc -C opt-level=s -Cpanic=abort" \
CARGO_TARGET_DIR=$(realpath .)/cargo \ CARGO_TARGET_DIR=$(realpath .)/cargo \
cargo rustc --verbose \ cargo build --target=or1k-unknown-none \
--manifest-path $(realpath $(RUNTIME_DIRECTORY)/../firmware/runtime/Cargo.toml) \ --manifest-path $(realpath $(RUNTIME_DIRECTORY)/../firmware/runtime/Cargo.toml)
--target=or1k-unknown-none -- \
$(shell cat $(BUILDINC_DIRECTORY)/generated/rust-cfg) \
-C target-feature=+mul,+div,+ffl1,+cmov,+addc -C opt-level=s -Cpanic=abort \
-L../libcompiler-rt
runtime.elf: $(OBJECTS) $(RUSTOUT_DIRECTORY)/libruntime.a runtime.elf: $(OBJECTS) $(RUSTOUT)/libruntime.a
$(LD) $(LDFLAGS) \ $(LD) $(LDFLAGS) \
-T $(RUNTIME_DIRECTORY)/runtime.ld \ -T $(RUNTIME_DIRECTORY)/runtime.ld \
-o $@ \ -o $@ \
@ -49,18 +45,14 @@ runtime.elf: $(OBJECTS) $(RUSTOUT_DIRECTORY)/libruntime.a
-lbase-nofloat -lcompiler-rt -lalloc -llwip -lbase-nofloat -lcompiler-rt -lalloc -llwip
@chmod -x $@ @chmod -x $@
.PHONY: $(RUSTOUT_DIRECTORY)/libksupport.a .PHONY: $(RUSTOUT_KSUPPORT)/libksupport.a
$(RUSTOUT_DIRECTORY)/libksupport.a: $(RUSTOUT_KSUPPORT)/libksupport.a:
CARGO_TARGET_DIR=$(realpath .)/cargo \ RUSTFLAGS="-C target-feature=+mul,+div,+ffl1,+cmov,+addc -C opt-level=s -Cpanic=unwind" \
cargo rustc --verbose \ CARGO_TARGET_DIR=$(realpath .)/cargo-ksupport \
--manifest-path $(realpath $(RUNTIME_DIRECTORY)/../firmware/libksupport/Cargo.toml) \ cargo build --target=or1k-unknown-none \
--target=or1k-unknown-none -- \ --manifest-path $(realpath $(RUNTIME_DIRECTORY)/../firmware/libksupport/Cargo.toml)
$(shell cat $(BUILDINC_DIRECTORY)/generated/rust-cfg) \
--cfg ksupport \
-C target-feature=+mul,+div,+ffl1,+cmov,+addc -C opt-level=s -Cpanic=unwind \
-L../libcompiler-rt
ksupport.elf: $(OBJECTS_KSUPPORT) $(RUSTOUT_DIRECTORY)/libksupport.a ksupport.elf: $(OBJECTS_KSUPPORT) $(RUSTOUT_KSUPPORT)/libksupport.a
$(LD) $(LDFLAGS) \ $(LD) $(LDFLAGS) \
--eh-frame-hdr \ --eh-frame-hdr \
-T $(RUNTIME_DIRECTORY)/ksupport.ld \ -T $(RUNTIME_DIRECTORY)/ksupport.ld \