From c2d86c4f67d289ae38463fda8127e6d969f7d8ff Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 3 Jan 2017 20:12:56 +0000 Subject: [PATCH] firmware: apply build flags globally, move --cfg handling to build.rs. --- artiq/firmware/libksupport/Cargo.toml | 1 + artiq/firmware/libksupport/build.rs | 17 ++++++++++++ artiq/firmware/runtime/build.rs | 11 +++++++- artiq/runtime/Makefile | 38 +++++++++++---------------- 4 files changed, 43 insertions(+), 24 deletions(-) create mode 100644 artiq/firmware/libksupport/build.rs diff --git a/artiq/firmware/libksupport/Cargo.toml b/artiq/firmware/libksupport/Cargo.toml index d009c2267..47c27a97d 100644 --- a/artiq/firmware/libksupport/Cargo.toml +++ b/artiq/firmware/libksupport/Cargo.toml @@ -2,6 +2,7 @@ authors = ["M-Labs"] name = "ksupport" version = "0.0.0" +build = "build.rs" [lib] name = "ksupport" diff --git a/artiq/firmware/libksupport/build.rs b/artiq/firmware/libksupport/build.rs new file mode 100644 index 000000000..302f197c9 --- /dev/null +++ b/artiq/firmware/libksupport/build.rs @@ -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"); +} diff --git a/artiq/firmware/runtime/build.rs b/artiq/firmware/runtime/build.rs index 36a05671d..5ab08cdd6 100644 --- a/artiq/firmware/runtime/build.rs +++ b/artiq/firmware/runtime/build.rs @@ -2,13 +2,22 @@ extern crate walkdir; use std::env; use std::fs::File; -use std::io::Write; +use std::io::{Write, BufRead, BufReader}; use std::path::Path; use std::process::Command; use walkdir::WalkDir; 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 dest_path = Path::new(&out_dir).join("git_info.rs"); let mut f = File::create(&dest_path).unwrap(); diff --git a/artiq/runtime/Makefile b/artiq/runtime/Makefile index 55e261fc0..602774e83 100644 --- a/artiq/runtime/Makefile +++ b/artiq/runtime/Makefile @@ -6,9 +6,8 @@ PYTHON ?= python3.5 OBJECTS := flash_storage.o main.o OBJECTS_KSUPPORT := ksupport_glue.o artiq_personality.o -RUSTOUT_DIRECTORY := cargo/or1k-unknown-none/debug -CORE_IO_COMMIT := d40c593f42fafbac1ff3d827f6df96338b5b7d8b -export CORE_IO_COMMIT +RUSTOUT := cargo/or1k-unknown-none/debug +RUSTOUT_KSUPPORT := cargo-ksupport/or1k-unknown-none/debug CFLAGS += \ -I$(LIBALLOC_DIRECTORY) \ @@ -31,17 +30,14 @@ LDFLAGS += --gc-sections \ all: runtime.bin runtime.fbi -.PHONY: $(RUSTOUT_DIRECTORY)/libruntime.a -$(RUSTOUT_DIRECTORY)/libruntime.a: ksupport.elf +.PHONY: $(RUSTOUT)/libruntime.a +$(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 rustc --verbose \ - --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 + cargo build --target=or1k-unknown-none \ + --manifest-path $(realpath $(RUNTIME_DIRECTORY)/../firmware/runtime/Cargo.toml) -runtime.elf: $(OBJECTS) $(RUSTOUT_DIRECTORY)/libruntime.a +runtime.elf: $(OBJECTS) $(RUSTOUT)/libruntime.a $(LD) $(LDFLAGS) \ -T $(RUNTIME_DIRECTORY)/runtime.ld \ -o $@ \ @@ -49,18 +45,14 @@ runtime.elf: $(OBJECTS) $(RUSTOUT_DIRECTORY)/libruntime.a -lbase-nofloat -lcompiler-rt -lalloc -llwip @chmod -x $@ -.PHONY: $(RUSTOUT_DIRECTORY)/libksupport.a -$(RUSTOUT_DIRECTORY)/libksupport.a: - CARGO_TARGET_DIR=$(realpath .)/cargo \ - cargo rustc --verbose \ - --manifest-path $(realpath $(RUNTIME_DIRECTORY)/../firmware/libksupport/Cargo.toml) \ - --target=or1k-unknown-none -- \ - $(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 +.PHONY: $(RUSTOUT_KSUPPORT)/libksupport.a +$(RUSTOUT_KSUPPORT)/libksupport.a: + RUSTFLAGS="-C target-feature=+mul,+div,+ffl1,+cmov,+addc -C opt-level=s -Cpanic=unwind" \ + CARGO_TARGET_DIR=$(realpath .)/cargo-ksupport \ + cargo build --target=or1k-unknown-none \ + --manifest-path $(realpath $(RUNTIME_DIRECTORY)/../firmware/libksupport/Cargo.toml) -ksupport.elf: $(OBJECTS_KSUPPORT) $(RUSTOUT_DIRECTORY)/libksupport.a +ksupport.elf: $(OBJECTS_KSUPPORT) $(RUSTOUT_KSUPPORT)/libksupport.a $(LD) $(LDFLAGS) \ --eh-frame-hdr \ -T $(RUNTIME_DIRECTORY)/ksupport.ld \