From c4b88cc1e63acb83bccd492c1b9e320af8edbad7 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 3 Mar 2018 20:33:19 -0700 Subject: [PATCH 1/3] Build ctype with header --- Cargo.lock | 9 +++++ Cargo.toml | 1 + src/ctype/Cargo.toml | 11 ++++++ src/ctype/build.rs | 11 ++++++ src/ctype/cbindgen.toml | 6 +++ src/ctype/src/lib.rs | 82 +++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + src/todo/ctype/lib.rs | 76 -------------------------------------- 8 files changed, 121 insertions(+), 76 deletions(-) create mode 100644 src/ctype/Cargo.toml create mode 100644 src/ctype/build.rs create mode 100644 src/ctype/cbindgen.toml create mode 100644 src/ctype/src/lib.rs delete mode 100644 src/todo/ctype/lib.rs diff --git a/Cargo.lock b/Cargo.lock index a485ed6ca6..60bc0e45a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,6 +62,14 @@ dependencies = [ "platform 0.1.0", ] +[[package]] +name = "ctype" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.0", + "platform 0.1.0", +] + [[package]] name = "dtoa" version = "0.4.2" @@ -212,6 +220,7 @@ name = "relibc" version = "0.1.0" dependencies = [ "compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)", + "ctype 0.1.0", "fcntl 0.1.0", "platform 0.1.0", "stdio 0.1.0", diff --git a/Cargo.toml b/Cargo.toml index e84ea2cf04..d012812b38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ members = ["crt0"] [dependencies] compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins.git", default-features = false, features = ["mem"] } platform = { path = "platform" } +ctype = { path = "src/ctype" } fcntl = { path = "src/fcntl" } stdio = { path = "src/stdio" } stdlib = { path = "src/stdlib" } diff --git a/src/ctype/Cargo.toml b/src/ctype/Cargo.toml new file mode 100644 index 0000000000..d0ae7b3fb3 --- /dev/null +++ b/src/ctype/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "ctype" +version = "0.1.0" +authors = ["Jeremy Soller "] +build = "build.rs" + +[build-dependencies] +cbindgen = { path = "../../cbindgen" } + +[dependencies] +platform = { path = "../../platform" } diff --git a/src/ctype/build.rs b/src/ctype/build.rs new file mode 100644 index 0000000000..089fee8df3 --- /dev/null +++ b/src/ctype/build.rs @@ -0,0 +1,11 @@ +extern crate cbindgen; + +use std::{env, fs}; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + fs::create_dir_all("../../target/include").expect("failed to create include directory"); + cbindgen::generate(crate_dir) + .expect("failed to generate bindings") + .write_to_file("../../target/include/ctype.h"); +} diff --git a/src/ctype/cbindgen.toml b/src/ctype/cbindgen.toml new file mode 100644 index 0000000000..db7a3a0bc8 --- /dev/null +++ b/src/ctype/cbindgen.toml @@ -0,0 +1,6 @@ +sys_includes = [] +include_guard = "_CTYPE_H" +language = "C" + +[enum] +prefix_with_name = true diff --git a/src/ctype/src/lib.rs b/src/ctype/src/lib.rs new file mode 100644 index 0000000000..be49d70ee4 --- /dev/null +++ b/src/ctype/src/lib.rs @@ -0,0 +1,82 @@ +//! ctype implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/ctype.h.html + +#![no_std] + +extern crate platform; + +use platform::types::*; + +#[no_mangle] +pub extern "C" fn isalnum(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn isalpha(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn isascii(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn iscntrl(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn isdigit(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn isgraph(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn islower(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn isprint(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn ispunct(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn isspace(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn isupper(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn isxdigit(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn toascii(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn tolower(c: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn toupper(c: c_int) -> c_int { + unimplemented!(); +} diff --git a/src/lib.rs b/src/lib.rs index 0e04380255..d1cdd8af0b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ extern crate compiler_builtins; extern crate platform; +extern crate ctype; extern crate fcntl; extern crate stdio; extern crate stdlib; diff --git a/src/todo/ctype/lib.rs b/src/todo/ctype/lib.rs deleted file mode 100644 index 4d83de3f89..0000000000 --- a/src/todo/ctype/lib.rs +++ /dev/null @@ -1,76 +0,0 @@ -/* automatically generated by rust-bindgen */ - -#[no_mangle] -pub extern "C" fn isalnum(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn isalpha(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn isascii(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn iscntrl(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn isdigit(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn isgraph(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn islower(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn isprint(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn ispunct(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn isspace(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn isupper(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn isxdigit(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn toascii(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn tolower(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} - -#[no_mangle] -pub extern "C" fn toupper(c: libc::c_int) -> libc::c_int { - unimplemented!(); -} From a9f2e9a9a7f861c9d51b82a6e40c23faeb063764 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 3 Mar 2018 20:48:37 -0700 Subject: [PATCH 2/3] Add template --- include/bits/wchar.h | 7 +++++++ platform/src/types.rs | 1 + src/template/Cargo.toml | 11 +++++++++++ src/template/build.rs | 11 +++++++++++ src/template/cbindgen.toml | 6 ++++++ src/template/src/lib.rs | 14 ++++++++++++++ 6 files changed, 50 insertions(+) create mode 100644 include/bits/wchar.h create mode 100644 src/template/Cargo.toml create mode 100644 src/template/build.rs create mode 100644 src/template/cbindgen.toml create mode 100644 src/template/src/lib.rs diff --git a/include/bits/wchar.h b/include/bits/wchar.h new file mode 100644 index 0000000000..98216dfb0f --- /dev/null +++ b/include/bits/wchar.h @@ -0,0 +1,7 @@ +#ifndef _BITS_WCHAR_H +#define _BITS_WCHAR_H + +typedef signed short wchar_t; +typedef signed int wint_t; + +#endif /* _BITS_WCHAR_H */ diff --git a/platform/src/types.rs b/platform/src/types.rs index bb87c740c0..dbbc2be301 100644 --- a/platform/src/types.rs +++ b/platform/src/types.rs @@ -43,6 +43,7 @@ pub type c_long = i64; pub type c_ulong = u64; pub type wchar_t = i16; +pub type wint_t = i32; pub type off_t = c_long; pub type mode_t = u16; diff --git a/src/template/Cargo.toml b/src/template/Cargo.toml new file mode 100644 index 0000000000..4021963f1f --- /dev/null +++ b/src/template/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "template" +version = "0.1.0" +authors = ["Jeremy Soller "] +build = "build.rs" + +[build-dependencies] +cbindgen = { path = "../../cbindgen" } + +[dependencies] +platform = { path = "../../platform" } diff --git a/src/template/build.rs b/src/template/build.rs new file mode 100644 index 0000000000..35b5d3bd87 --- /dev/null +++ b/src/template/build.rs @@ -0,0 +1,11 @@ +extern crate cbindgen; + +use std::{env, fs}; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + fs::create_dir_all("../../target/include").expect("failed to create include directory"); + cbindgen::generate(crate_dir) + .expect("failed to generate bindings") + .write_to_file("../../target/include/template.h"); +} diff --git a/src/template/cbindgen.toml b/src/template/cbindgen.toml new file mode 100644 index 0000000000..bf4ccefced --- /dev/null +++ b/src/template/cbindgen.toml @@ -0,0 +1,6 @@ +sys_includes = [] +include_guard = "_TEMPLATE_H" +language = "C" + +[enum] +prefix_with_name = true diff --git a/src/template/src/lib.rs b/src/template/src/lib.rs new file mode 100644 index 0000000000..e0c83c7cef --- /dev/null +++ b/src/template/src/lib.rs @@ -0,0 +1,14 @@ +//! template implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/template.h.html + +#![no_std] + +extern crate platform; + +use platform::types::*; + +/* +#[no_mangle] +pub extern "C" fn func(args) -> c_int { + unimplemented!(); +} +*/ From 352f485649092543575898802a5775317941b793 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 3 Mar 2018 20:52:10 -0700 Subject: [PATCH 3/3] Build grp header --- Cargo.lock | 9 +++++++ Cargo.toml | 1 + src/grp/Cargo.toml | 11 +++++++++ src/grp/build.rs | 11 +++++++++ src/grp/cbindgen.toml | 6 +++++ src/{todo/grp => grp/src}/lib.rs | 41 +++++++++++++++++++------------- src/lib.rs | 1 + 7 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 src/grp/Cargo.toml create mode 100644 src/grp/build.rs create mode 100644 src/grp/cbindgen.toml rename src/{todo/grp => grp/src}/lib.rs (57%) diff --git a/Cargo.lock b/Cargo.lock index 60bc0e45a0..8be22825db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,6 +97,14 @@ name = "fuchsia-zircon-sys" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "grp" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.0", + "platform 0.1.0", +] + [[package]] name = "itoa" version = "0.3.4" @@ -222,6 +230,7 @@ dependencies = [ "compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)", "ctype 0.1.0", "fcntl 0.1.0", + "grp 0.1.0", "platform 0.1.0", "stdio 0.1.0", "stdlib 0.1.0", diff --git a/Cargo.toml b/Cargo.toml index d012812b38..af003fd336 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-built platform = { path = "platform" } ctype = { path = "src/ctype" } fcntl = { path = "src/fcntl" } +grp = { path = "src/grp" } stdio = { path = "src/stdio" } stdlib = { path = "src/stdlib" } string = { path = "src/string" } diff --git a/src/grp/Cargo.toml b/src/grp/Cargo.toml new file mode 100644 index 0000000000..d09fdca34c --- /dev/null +++ b/src/grp/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "grp" +version = "0.1.0" +authors = ["Jeremy Soller "] +build = "build.rs" + +[build-dependencies] +cbindgen = { path = "../../cbindgen" } + +[dependencies] +platform = { path = "../../platform" } diff --git a/src/grp/build.rs b/src/grp/build.rs new file mode 100644 index 0000000000..9ee6c69617 --- /dev/null +++ b/src/grp/build.rs @@ -0,0 +1,11 @@ +extern crate cbindgen; + +use std::{env, fs}; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + fs::create_dir_all("../../target/include").expect("failed to create include directory"); + cbindgen::generate(crate_dir) + .expect("failed to generate bindings") + .write_to_file("../../target/include/grp.h"); +} diff --git a/src/grp/cbindgen.toml b/src/grp/cbindgen.toml new file mode 100644 index 0000000000..5b249723f8 --- /dev/null +++ b/src/grp/cbindgen.toml @@ -0,0 +1,6 @@ +sys_includes = [] +include_guard = "_GRP_H" +language = "C" + +[enum] +prefix_with_name = true diff --git a/src/todo/grp/lib.rs b/src/grp/src/lib.rs similarity index 57% rename from src/todo/grp/lib.rs rename to src/grp/src/lib.rs index 3b7bbd4034..c80ee95aff 100644 --- a/src/todo/grp/lib.rs +++ b/src/grp/src/lib.rs @@ -1,24 +1,26 @@ -/* automatically generated by rust-bindgen */ +//! grp implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/grp.h.html + +#![no_std] + +extern crate platform; + +use platform::types::*; + #[repr(C)] -#[derive(Debug, Copy)] pub struct group { - pub gr_name: *mut libc::c_char, - pub gr_passwd: *mut libc::c_char, + pub gr_name: *mut c_char, + pub gr_passwd: *mut c_char, pub gr_gid: gid_t, - pub gr_mem: *mut *mut libc::c_char, -} -impl Clone for group { - fn clone(&self) -> Self { - *self - } + pub gr_mem: *mut *mut c_char, } + #[no_mangle] pub extern "C" fn getgrgid(gid: gid_t) -> *mut group { unimplemented!(); } #[no_mangle] -pub extern "C" fn getgrnam(name: *const libc::c_char) -> *mut group { +pub extern "C" fn getgrnam(name: *const c_char) -> *mut group { unimplemented!(); } @@ -26,21 +28,21 @@ pub extern "C" fn getgrnam(name: *const libc::c_char) -> *mut group { pub extern "C" fn getgrgid_r( gid: gid_t, grp: *mut group, - buffer: *mut libc::c_char, + buffer: *mut c_char, bufsize: usize, result: *mut *mut group, -) -> libc::c_int { +) -> c_int { unimplemented!(); } #[no_mangle] pub extern "C" fn getgrnam_r( - name: *const libc::c_char, + name: *const c_char, grp: *mut group, - buffer: *mut libc::c_char, + buffer: *mut c_char, bufsize: usize, result: *mut *mut group, -) -> libc::c_int { +) -> c_int { unimplemented!(); } @@ -58,3 +60,10 @@ pub extern "C" fn endgrent() { pub extern "C" fn setgrent() { unimplemented!(); } + +/* +#[no_mangle] +pub extern "C" fn func(args) -> c_int { + unimplemented!(); +} +*/ diff --git a/src/lib.rs b/src/lib.rs index d1cdd8af0b..63815d70be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ extern crate platform; extern crate ctype; extern crate fcntl; +extern crate grp; extern crate stdio; extern crate stdlib; extern crate string;