Skip to content
Snippets Groups Projects
Commit 2253ef60 authored by Graham MacDonald's avatar Graham MacDonald Committed by Jeremy Soller
Browse files

Remove vendored cbindgen, use cbindgen dependency to generate includes in build.rs

parent d7a859fb
No related branches found
No related tags found
No related merge requests found
[submodule "openlibm"] [submodule "openlibm"]
path = openlibm path = openlibm
url = https://gitlab.redox-os.org/redox-os/openlibm.git url = https://gitlab.redox-os.org/redox-os/openlibm.git
[submodule "cbindgen"]
path = cbindgen
url = https://github.com/eqrion/cbindgen.git
[submodule "ralloc"] [submodule "ralloc"]
path = ralloc path = ralloc
url = https://gitlab.redox-os.org/redox-os/ralloc.git url = https://gitlab.redox-os.org/redox-os/ralloc.git
......
This diff is collapsed.
...@@ -10,9 +10,10 @@ crate-type = ["staticlib"] ...@@ -10,9 +10,10 @@ crate-type = ["staticlib"]
[workspace] [workspace]
members = ["src/crt0", "src/crti", "src/crtn", "src/ld_so"] members = ["src/crt0", "src/crti", "src/crtn", "src/ld_so"]
exclude = ["cbindgen", "core_io", "ralloc"] exclude = ["core_io", "ralloc"]
[build-dependencies] [build-dependencies]
cbindgen = "0.13.2"
cc = "1.0.25" cc = "1.0.25"
[dependencies] [dependencies]
......
...@@ -33,13 +33,12 @@ SRC=\ ...@@ -33,13 +33,12 @@ SRC=\
Cargo.* \ Cargo.* \
$(shell find src -type f) $(shell find src -type f)
.PHONY: all clean fmt headers install install-headers libs test .PHONY: all clean fmt install install-headers libs test
all: | headers libs all: | libs
clean: clean:
$(CARGO) clean $(CARGO) clean
$(CARGO) clean --manifest-path cbindgen/Cargo.toml
$(MAKE) -C tests clean $(MAKE) -C tests clean
rm -rf sysroot rm -rf sysroot
...@@ -49,12 +48,10 @@ check: ...@@ -49,12 +48,10 @@ check:
fmt: fmt:
./fmt.sh ./fmt.sh
headers: $(BUILD)/include install-headers: libs
install-headers: headers
mkdir -pv "$(DESTDIR)/include" mkdir -pv "$(DESTDIR)/include"
cp -rv "include"/* "$(DESTDIR)/include" cp -rv "include"/* "$(DESTDIR)/include"
cp -rv "$(BUILD)/include"/* "$(DESTDIR)/include" cp -rv "target/include"/* "$(DESTDIR)/include"
cp -v "openlibm/include"/*.h "$(DESTDIR)/include" cp -v "openlibm/include"/*.h "$(DESTDIR)/include"
cp -v "openlibm/src"/*.h "$(DESTDIR)/include" cp -v "openlibm/src"/*.h "$(DESTDIR)/include"
cp -v "pthreads-emb/"*.h "$(DESTDIR)/include" cp -v "pthreads-emb/"*.h "$(DESTDIR)/include"
...@@ -168,13 +165,6 @@ $(BUILD)/release/ld_so: $(BUILD)/release/ld_so.o $(BUILD)/release/crti.o $(BUILD ...@@ -168,13 +165,6 @@ $(BUILD)/release/ld_so: $(BUILD)/release/ld_so.o $(BUILD)/release/crti.o $(BUILD
# Other targets # Other targets
$(BUILD)/include: $(SRC)
rm -rf $@ $@.partial
mkdir -p $@.partial
./include.sh $@.partial
mv $@.partial $@
touch $@
$(BUILD)/openlibm: openlibm $(BUILD)/openlibm: openlibm
rm -rf $@ $@.partial rm -rf $@ $@.partial
mkdir -p $(BUILD) mkdir -p $(BUILD)
...@@ -182,8 +172,8 @@ $(BUILD)/openlibm: openlibm ...@@ -182,8 +172,8 @@ $(BUILD)/openlibm: openlibm
mv $@.partial $@ mv $@.partial $@
touch $@ touch $@
$(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm $(BUILD)/include $(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm $(BUILD)/release/librelibc.a
$(MAKE) CC=$(CC) CPPFLAGS="-fno-stack-protector -I$(shell pwd)/include -I $(shell pwd)/$(BUILD)/include" -C $< libopenlibm.a $(MAKE) CC=$(CC) CPPFLAGS="-fno-stack-protector -I $(shell pwd)/include -I $(shell pwd)/target/include" -C $< libopenlibm.a
$(BUILD)/pthreads-emb: pthreads-emb $(BUILD)/pthreads-emb: pthreads-emb
rm -rf $@ $@.partial rm -rf $@ $@.partial
...@@ -192,5 +182,5 @@ $(BUILD)/pthreads-emb: pthreads-emb ...@@ -192,5 +182,5 @@ $(BUILD)/pthreads-emb: pthreads-emb
mv $@.partial $@ mv $@.partial $@
touch $@ touch $@
$(BUILD)/pthreads-emb/libpthread.a: $(BUILD)/pthreads-emb $(BUILD)/include $(BUILD)/pthreads-emb/libpthread.a: $(BUILD)/pthreads-emb $(BUILD)/release/librelibc.a
$(MAKE) CC=$(CC) CFLAGS="-fno-stack-protector -I$(shell pwd)/include -I $(shell pwd)/$(BUILD)/include" -C $< libpthread.a $(MAKE) CC=$(CC) CFLAGS="-fno-stack-protector -I $(shell pwd)/include -I $(shell pwd)/target/include" -C $< libpthread.a
extern crate cbindgen;
extern crate cc; extern crate cc;
use std::{env, fs}; use std::{env, fs, fs::DirEntry, path::Path};
// include src/header directories that don't start with '_'
fn include_dir(d: &DirEntry) -> bool {
d.metadata().map(|m| m.is_dir()).unwrap_or(false)
&& d.path()
.iter()
.nth(2)
.map_or(false, |c| c.to_str().map_or(false, |x| !x.starts_with("_")))
}
fn generate_bindings(cbindgen_config_path: &Path) {
let relative_path = cbindgen_config_path
.strip_prefix("src/header")
.ok()
.and_then(|p| p.parent())
.and_then(|p| p.to_str())
.unwrap()
.replace("_", "/");
let header_path = Path::new("target/include")
.join(&relative_path)
.with_extension("h");
let mod_path = cbindgen_config_path.with_file_name("mod.rs");
let config = cbindgen::Config::from_file(cbindgen_config_path).unwrap();
cbindgen::Builder::new()
.with_config(config)
.with_src(mod_path)
.generate()
.expect("Unable to generate bindings")
.write_to_file(header_path);
}
fn main() { fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
// Generate C includes
// - based on contents of src/header/**
// - headers written to target/include
fs::read_dir(&Path::new("src/header"))
.unwrap()
.into_iter()
.filter_map(Result::ok)
.filter(|d| include_dir(d))
.map(|d| d.path().as_path().join("cbindgen.toml"))
.filter(|p| p.exists())
.for_each(|p| {
println!("cargo:rerun-if-changed={:?}", p.parent().unwrap());
println!("cargo:rerun-if-changed={:?}", p);
println!("cargo:rerun-if-changed={:?}", p.with_file_name("mod.rs"));
generate_bindings(&p);
});
cc::Build::new() cc::Build::new()
.flag("-nostdinc") .flag("-nostdinc")
.flag("-nostdlib") .flag("-nostdlib")
......
Subproject commit e19526e00b3fe6921b881682147a1fe5d6b64124
#!/usr/bin/env bash
SUPRESS_ALL_THE_ERRORS=yes
set -e
include="$(realpath "$1")"
cargo build --release --manifest-path cbindgen/Cargo.toml
cbindgen="$(realpath cbindgen/target/release/cbindgen)"
if [ "$SUPRESS_ALL_THE_ERRORS" = "yes" ]; then
echo -e "\e[91mNote: Warnings by cbindgen are suppressed in include.sh.\e[0m"
fi
jobs=()
for config in src/header/*/cbindgen.toml
do
dir="$(dirname "$config")"
name="$(basename "$dir")"
if [ "${name:0:1}" != "_" ]
then
header="$include/${name/_//}.h"
pushd "$dir" > /dev/null
echo "$dir"
cbindgen_cmd='"$cbindgen" -c cbindgen.toml -o "$header" mod.rs'
if [ "$SUPRESS_ALL_THE_ERRORS" = "yes" ]; then
eval "$cbindgen_cmd" 2>&1 | (grep "^ERROR" -A 3 || true) &
else
eval "$cbindgen_cmd" &
fi
jobs+=($!)
popd > /dev/null
fi
done
for job in "${jobs[@]}"
do
wait "$job"
done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment