Simplify relibc test recipe replay
This commit is contained in:
@@ -65,186 +65,3 @@ index 9a3978dc..906ad525 100644
|
||||
|
||||
// Defined for compatibility
|
||||
pub const O_NDELAY: c_int = O_NONBLOCK;
|
||||
diff --git a/src/header/mod.rs b/src/header/mod.rs
|
||||
index d3a7ba75..4cdc9f1d 100644
|
||||
--- a/src/header/mod.rs
|
||||
+++ b/src/header/mod.rs
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
pub mod _aio;
|
||||
pub mod _fenv;
|
||||
+pub mod arpa_nameser;
|
||||
pub mod arpa_inet;
|
||||
pub mod assert;
|
||||
pub mod bits_arpainet;
|
||||
@@ -66,6 +67,7 @@ pub mod pty;
|
||||
pub mod pwd;
|
||||
// TODO: re_comp.h (deprecated)
|
||||
pub mod regex;
|
||||
+pub mod resolv;
|
||||
// TODO: regexp.h (deprecated)
|
||||
pub mod sched;
|
||||
// TODO: search.h
|
||||
diff --git a/src/header/arpa_nameser/cbindgen.toml b/src/header/arpa_nameser/cbindgen.toml
|
||||
new file mode 100644
|
||||
--- /dev/null
|
||||
+++ b/src/header/arpa_nameser/cbindgen.toml
|
||||
@@ -0,0 +1,9 @@
|
||||
+sys_includes = ["sys/types.h", "stdint.h"]
|
||||
+include_guard = "_ARPA_NAMESER_H"
|
||||
+trailer = """
|
||||
+typedef struct HEADER HEADER;
|
||||
+"""
|
||||
+language = "C"
|
||||
+style = "Tag"
|
||||
+no_includes = true
|
||||
+cpp_compat = true
|
||||
diff --git a/src/header/arpa_nameser/mod.rs b/src/header/arpa_nameser/mod.rs
|
||||
new file mode 100644
|
||||
--- /dev/null
|
||||
+++ b/src/header/arpa_nameser/mod.rs
|
||||
@@ -0,0 +1,74 @@
|
||||
+//! `arpa/nameser.h` compatibility surface.
|
||||
+
|
||||
+use crate::{
|
||||
+ header::errno::EINVAL,
|
||||
+ platform::{
|
||||
+ ERRNO,
|
||||
+ types::{c_char, c_int, c_uchar},
|
||||
+ },
|
||||
+};
|
||||
+
|
||||
+pub const HFIXEDSZ: c_int = 12;
|
||||
+pub const MAXDNAME: c_int = 256;
|
||||
+
|
||||
+#[repr(C)]
|
||||
+#[derive(Clone, Copy, Default)]
|
||||
+#[allow(non_camel_case_types)]
|
||||
+pub struct HEADER {
|
||||
+ pub id: u16,
|
||||
+ pub flags: u16,
|
||||
+ pub qdcount: u16,
|
||||
+ pub ancount: u16,
|
||||
+ pub nscount: u16,
|
||||
+ pub arcount: u16,
|
||||
+}
|
||||
+
|
||||
+#[unsafe(no_mangle)]
|
||||
+pub extern "C" fn _cbindgen_export_nameser_header(header: HEADER) {
|
||||
+ let _ = header;
|
||||
+}
|
||||
+
|
||||
+#[unsafe(no_mangle)]
|
||||
+pub unsafe extern "C" fn dn_expand(
|
||||
+ msg: *const c_uchar,
|
||||
+ eomorig: *const c_uchar,
|
||||
+ comp_dn: *const c_uchar,
|
||||
+ exp_dn: *mut c_char,
|
||||
+ length: c_int,
|
||||
+) -> c_int {
|
||||
+ if msg.is_null() || eomorig.is_null() || comp_dn.is_null() || exp_dn.is_null() || length <= 0 {
|
||||
+ ERRNO.set(EINVAL);
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ let mut src = comp_dn;
|
||||
+ let mut out = exp_dn.cast::<u8>();
|
||||
+ let end = unsafe { exp_dn.add(length as usize) }.cast::<u8>();
|
||||
+ let mut consumed: isize = 0;
|
||||
+ let mut first = true;
|
||||
+
|
||||
+ loop {
|
||||
+ if src >= eomorig {
|
||||
+ ERRNO.set(EINVAL);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ let len = unsafe { *src };
|
||||
+ src = unsafe { src.add(1) };
|
||||
+ consumed += 1;
|
||||
+ if len == 0 {
|
||||
+ if out >= end { ERRNO.set(EINVAL); return -1; }
|
||||
+ unsafe { *out = 0 };
|
||||
+ return consumed as c_int;
|
||||
+ }
|
||||
+ if len & 0xC0 != 0 { ERRNO.set(EINVAL); return -1; }
|
||||
+ if !first {
|
||||
+ if out >= end { ERRNO.set(EINVAL); return -1; }
|
||||
+ unsafe { *out = b'.' };
|
||||
+ out = unsafe { out.add(1) };
|
||||
+ }
|
||||
+ first = false;
|
||||
+ if unsafe { src.add(len as usize) } > eomorig || unsafe { out.add(len as usize) } >= end { ERRNO.set(EINVAL); return -1; }
|
||||
+ unsafe { core::ptr::copy_nonoverlapping(src, out, len as usize); out = out.add(len as usize); src = src.add(len as usize); }
|
||||
+ consumed += len as isize;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/header/resolv/cbindgen.toml b/src/header/resolv/cbindgen.toml
|
||||
new file mode 100644
|
||||
--- /dev/null
|
||||
+++ b/src/header/resolv/cbindgen.toml
|
||||
@@ -0,0 +1,6 @@
|
||||
+sys_includes = ["sys/types.h", "netdb.h"]
|
||||
+include_guard = "_RESOLV_H"
|
||||
+language = "C"
|
||||
+style = "Tag"
|
||||
+no_includes = true
|
||||
+cpp_compat = true
|
||||
diff --git a/src/header/resolv/mod.rs b/src/header/resolv/mod.rs
|
||||
new file mode 100644
|
||||
--- /dev/null
|
||||
+++ b/src/header/resolv/mod.rs
|
||||
@@ -0,0 +1,54 @@
|
||||
+//! `resolv.h` bounded compatibility surface.
|
||||
+
|
||||
+use crate::{
|
||||
+ header::{arpa_nameser::dn_expand, errno::ENOSYS, netdb},
|
||||
+ platform::{
|
||||
+ ERRNO,
|
||||
+ types::{c_char, c_int, c_uchar},
|
||||
+ },
|
||||
+};
|
||||
+
|
||||
+pub const RES_INIT: c_int = 0x0000_0001;
|
||||
+pub const RES_DEBUG: c_int = 0x0000_0002;
|
||||
+pub const RES_USE_EDNS0: c_int = 0x0008_0000;
|
||||
+pub const RES_USE_DNSSEC: c_int = 0x0010_0000;
|
||||
+
|
||||
+#[repr(C)]
|
||||
+#[derive(Clone, Copy, Default)]
|
||||
+#[allow(non_camel_case_types)]
|
||||
+pub struct __res_state {
|
||||
+ pub options: c_int,
|
||||
+}
|
||||
+
|
||||
+pub type res_state = *mut __res_state;
|
||||
+
|
||||
+#[unsafe(no_mangle)]
|
||||
+pub static mut _res: __res_state = __res_state { options: 0 };
|
||||
+
|
||||
+#[unsafe(no_mangle)]
|
||||
+pub extern "C" fn _cbindgen_export_res_state(state: __res_state) {
|
||||
+ let _ = state;
|
||||
+}
|
||||
+
|
||||
+#[unsafe(no_mangle)]
|
||||
+pub unsafe extern "C" fn res_init() -> c_int {
|
||||
+ unsafe { _res.options |= RES_INIT; }
|
||||
+ 0
|
||||
+}
|
||||
+
|
||||
+#[unsafe(no_mangle)]
|
||||
+pub unsafe extern "C" fn res_query(_dname: *const c_char, _class: c_int, _rtype: c_int, _answer: *mut c_uchar, _anslen: c_int) -> c_int {
|
||||
+ netdb::H_ERRNO.set(netdb::NO_DATA);
|
||||
+ ERRNO.set(ENOSYS);
|
||||
+ -1
|
||||
+}
|
||||
+
|
||||
+#[unsafe(no_mangle)]
|
||||
+pub unsafe extern "C" fn res_search(dname: *const c_char, class: c_int, rtype: c_int, answer: *mut c_uchar, anslen: c_int) -> c_int {
|
||||
+ unsafe { res_query(dname, class, rtype, answer, anslen) }
|
||||
+}
|
||||
+
|
||||
+#[unsafe(no_mangle)]
|
||||
+pub unsafe extern "C" fn __dn_expand(msg: *const c_uchar, eomorig: *const c_uchar, comp_dn: *const c_uchar, exp_dn: *mut c_char, length: c_int) -> c_int {
|
||||
+ unsafe { dn_expand(msg, eomorig, comp_dn, exp_dn, length) }
|
||||
+}
|
||||
|
||||
@@ -2,19 +2,11 @@
|
||||
git = "https://gitlab.redox-os.org/redox-os/relibc.git"
|
||||
patches = [
|
||||
"../../../local/patches/relibc/redox.patch",
|
||||
"../../../local/patches/relibc/P0-strtold-cpp-linkage-and-compat.patch",
|
||||
"../../../local/patches/relibc/P3-eventfd.patch",
|
||||
"../../../local/patches/relibc/P3-signalfd.patch",
|
||||
"../../../local/patches/relibc/P3-signalfd-header.patch",
|
||||
"../../../local/patches/relibc/P3-timerfd.patch",
|
||||
"../../../local/patches/relibc/P3-open-memstream.patch",
|
||||
"../../../local/patches/relibc/P3-socket-flags.patch",
|
||||
"../../../local/patches/relibc/P3-ifaddrs-net_if.patch",
|
||||
"../../../local/patches/relibc/P3-waitid.patch",
|
||||
"../../../local/patches/relibc/P3-waitid-header.patch",
|
||||
"../../../local/patches/relibc/P3-sysv-ipc.patch",
|
||||
"../../../local/patches/relibc/P3-sysv-sem-impl.patch",
|
||||
"../../../local/patches/relibc/P3-sysv-shm-impl.patch",
|
||||
"../../../local/patches/relibc/P3-ipc-tests.patch",
|
||||
]
|
||||
|
||||
[build]
|
||||
|
||||
@@ -3,10 +3,28 @@ same_as = "../../core/relibc"
|
||||
|
||||
[build]
|
||||
template = "custom"
|
||||
dependencies = ["relibc"]
|
||||
script = """
|
||||
rsync -av --delete "${COOKBOOK_SOURCE}/" ./
|
||||
git -C "${COOKBOOK_SOURCE}" archive --format=tar HEAD | tar -xf -
|
||||
rsync -av "${COOKBOOK_SOURCE}/openlibm/" ./openlibm/
|
||||
|
||||
make install-tests DESTDIR="${COOKBOOK_STAGE}/home/user" NATIVE_LIBC=1 IS_REDOX=1
|
||||
patch -N -p1 < "${COOKBOOK_ROOT}/local/patches/relibc/redox.patch"
|
||||
|
||||
make headers TARGET="${TARGET}"
|
||||
|
||||
RELIBC_STAGE="${COOKBOOK_ROOT}/recipes/core/relibc/target/${TARGET}/stage"
|
||||
if [ ! -d "${RELIBC_STAGE}/usr" ]; then
|
||||
RELIBC_STAGE="${COOKBOOK_ROOT}/recipes/core/relibc/target/${TARGET}/stage.tmp"
|
||||
fi
|
||||
|
||||
mkdir -p "${COOKBOOK_SYSROOT}"
|
||||
rsync -av "${RELIBC_STAGE}/usr/" "${COOKBOOK_SYSROOT}/"
|
||||
rsync -av "./target/${TARGET}/include/" "${COOKBOOK_SYSROOT}/include/"
|
||||
|
||||
mkdir -p ./sysroot
|
||||
ln -sfn "${COOKBOOK_SYSROOT}" "./sysroot/${TARGET}"
|
||||
|
||||
make -j1 install-tests DESTDIR="${COOKBOOK_STAGE}/home/user" NATIVE_LIBC=0 IS_REDOX=1 SYSROOT="${COOKBOOK_SYSROOT}" SYSROOT_TARGET="${COOKBOOK_SYSROOT}"
|
||||
|
||||
if [ -n "$TESTBIN" ]; then
|
||||
"${COOKBOOK_REDOXER}" write-exec sh -c "cd /home/user/relibc-tests; make run-once TESTBIN=bins_dynamic/$TESTBIN"
|
||||
|
||||
@@ -5,9 +5,29 @@ same_as = "../../core/relibc"
|
||||
|
||||
[build]
|
||||
template = "custom"
|
||||
dependencies = ["relibc"]
|
||||
script = """
|
||||
git -C "${COOKBOOK_SOURCE}" archive --format=tar HEAD | tar -xf -
|
||||
rsync -av "${COOKBOOK_SOURCE}/openlibm/" ./openlibm/
|
||||
|
||||
patch -N -p1 < "${COOKBOOK_ROOT}/local/patches/relibc/redox.patch"
|
||||
|
||||
make headers TARGET="${TARGET}"
|
||||
|
||||
RELIBC_STAGE="${COOKBOOK_ROOT}/recipes/core/relibc/target/${TARGET}/stage"
|
||||
if [ ! -d "${RELIBC_STAGE}/usr" ]; then
|
||||
RELIBC_STAGE="${COOKBOOK_ROOT}/recipes/core/relibc/target/${TARGET}/stage.tmp"
|
||||
fi
|
||||
|
||||
mkdir -p "${COOKBOOK_SYSROOT}"
|
||||
rsync -av "${RELIBC_STAGE}/usr/" "${COOKBOOK_SYSROOT}/"
|
||||
rsync -av "./target/${TARGET}/include/" "${COOKBOOK_SYSROOT}/include/"
|
||||
|
||||
mkdir -p ./sysroot
|
||||
ln -sfn "${COOKBOOK_SYSROOT}" "./sysroot/${TARGET}"
|
||||
|
||||
mkdir -pv "${COOKBOOK_STAGE}/home/user/relibc-tests"
|
||||
cp -rv "${COOKBOOK_SOURCE}/tests" "${COOKBOOK_STAGE}/home/user/relibc-tests"
|
||||
cp -rv ./tests "${COOKBOOK_STAGE}/home/user/relibc-tests"
|
||||
"""
|
||||
|
||||
[package]
|
||||
|
||||
Reference in New Issue
Block a user