Update libtock's build script to not conflict with libtock_runtime's build script and remove the broken empty_main example.
I made changes to libtock_runtime's linker scripts and the changes were not having any effect.
Explanation: According to the cargo reference, build scripts should only write to OUT_DIR [1]. This is not enforced, and libtock's build script wrote `layout.ld` directly in `libtock`'s source directory. This works for libtock because rust-lld is executed in the cargo workspace directory, which is libtock's source directory, so the linker was able to find layout.ld. However, after libtock has been build once, when the linker runs for libtock_runtime, there are two layout.ld files present: the file in OUT_DIR from libtock_runtime's build script and a leftover layout.ld file from the last time libtock was compiled. The linker selected the layout.ld file in the libtock package, which is not the one we wanted it to select. There isn't a way to change this behavior by the linker.
To avoid this, I changed libtock's build script to copy its layout.ld into OUT_DIR, isolating it from libtock_runtime. I also removed layout.ld from .gitignore. So that the include from layout.ld to layout_generic.ld works, I also made it copy layout_generic.ld into OUT_DIR (the same way libtock_runtime's new build script works).
This then broke libtock_core's example, `empty_main`. libtock_core does not have a linker script mechanism, and its build was relying on the presence of layout.ld from libtock's build script. This is a bug, and was never caught.
I added the `empty_main` example before I redirected my libtock_platform efforts at Tock 2.0. At that time, I was planning to add libtock_runtime to libtock_core. However, when I changed my libtock_platform efforts to the Tock 2.0 ABI, it was no longer possible to add libtock_runtime to libtock_core. It also means that empty_main isn't very useful (it measures the size of code I'm replacing rather than refactoring), so I deleted it.
[1] https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script
diff --git a/.gitignore b/.gitignore
index ae858ab..2bcb93f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
/Cargo.lock
-/layout.ld
/platform
/target
diff --git a/build.rs b/build.rs
index b24d3d2..bc492f9 100644
--- a/build.rs
+++ b/build.rs
@@ -3,10 +3,11 @@
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
-use std::path::Path;
+use std::path::{Path, PathBuf};
use std::process;
static LAYOUT_FILE_NAME: &str = "layout.ld";
+static LAYOUT_GENERIC_FILENAME: &str = "layout_generic.ld";
fn main() {
static PLATFORM_ENV_VAR: &str = "PLATFORM";
@@ -19,6 +20,7 @@
println!("cargo:rerun-if-env-changed={}", KERNEL_HEAP_SIZE);
println!("cargo:rerun-if-changed={}", PLATFORM_FILE_NAME);
println!("cargo:rerun-if-changed={}", LAYOUT_FILE_NAME);
+ println!("cargo:rerun-if-changed={}", LAYOUT_GENERIC_FILENAME);
let platform_name =
read_env_var(PLATFORM_ENV_VAR).or_else(|| read_board_name_from_file(PLATFORM_FILE_NAME));
@@ -70,5 +72,20 @@
println!("Cannot find layout file {:?}", path);
process::exit(1);
}
- fs::copy(linker_file_name, LAYOUT_FILE_NAME).unwrap();
+ // Note: cargo fails if run in a path that is not valid Unicode, so this
+ // script doesn't need to handle non-Unicode paths. Also, OUT_DIR cannot be
+ // in a location with a newline in it, or we have no way to pass
+ // rustc-link-search to cargo.
+ let out_dir = &std::env::var("OUT_DIR").expect("Unable to read OUT_DIR");
+ if out_dir.contains('\n') {
+ panic!("Build path contains a newline, which is unsupported");
+ }
+ let out_layout_path: PathBuf = [out_dir, "layout.ld"].iter().collect();
+ fs::copy(linker_file_name, out_layout_path).unwrap();
+
+ // Copy the generic layout file into OUT_DIR.
+ let out_layout_generic: PathBuf = [out_dir, LAYOUT_GENERIC_FILENAME].iter().collect();
+ fs::copy(LAYOUT_GENERIC_FILENAME, out_layout_generic)
+ .expect("Unable to copy layout_generic.ld into OUT_DIR");
+ println!("cargo:rustc-link-search={}", out_dir);
}
diff --git a/core/examples/empty_main.rs b/core/examples/empty_main.rs
deleted file mode 100644
index a3644b7..0000000
--- a/core/examples/empty_main.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-// The most minimal libtock_core example possible. This file primarily exists
-// for code size measurement, as this should create the smallest-possible
-// libtock_core app.
-
-#![no_std]
-
-// If you don't *use* anything from libtock_core directly, cargo will not link
-// it into the executable. However, we still need the runtime and lang items.
-// Therefore a libtock_core app that doesn't directly mention anything in
-// libtock_core needs to explicitly declare its dependency on libtock_core as
-// follows.
-extern crate libtock_core;
-
-libtock_core::stack_size! {0x400}
-
-fn main() {}