From 2fe9e4c22bd9e6df579d87079faacc9897d814cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Mon, 10 Aug 2020 10:57:11 +0200 Subject: [PATCH] make it compatible with no_std environment --- rust/libnotcurses-sys/Cargo.toml | 7 ++++++- rust/libnotcurses-sys/build.rs | 2 ++ rust/libnotcurses-sys/src/cells.rs | 3 +-- rust/libnotcurses-sys/src/lib.rs | 8 +++++--- rust/libnotcurses-sys/src/plane.rs | 4 ++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/rust/libnotcurses-sys/Cargo.toml b/rust/libnotcurses-sys/Cargo.toml index 59e3edc31..7164a5822 100644 --- a/rust/libnotcurses-sys/Cargo.toml +++ b/rust/libnotcurses-sys/Cargo.toml @@ -19,7 +19,12 @@ categories = [ keywords = ["tui", "cli", "terminal", "ncurses", "ffi"] [dependencies] -libc = "0.2.74" +libc = {version = "0.2.74", default-features = false} +cty = "0.2.1" +# blocked by: https://github.com/Amanieu/cstr_core/issues/4 +# cstr_core = "0.2" +cstr_core = {path = "../../../../_temp_clones/cstr_core"} +libc-print = "0.1.13" [build-dependencies] bindgen = ">= 0.52.0" diff --git a/rust/libnotcurses-sys/build.rs b/rust/libnotcurses-sys/build.rs index f269c20e9..a0d81b9ec 100644 --- a/rust/libnotcurses-sys/build.rs +++ b/rust/libnotcurses-sys/build.rs @@ -21,6 +21,8 @@ fn main() { // The bindgen::Builder is the main entry point to bindgen, and lets you // build up options for the resulting bindings. let mut builder = bindgen::Builder::default() + .use_core() + .ctypes_prefix("cty") .clang_arg("-D_XOPEN_SOURCE") // The input header we would like to generate // builder for. diff --git a/rust/libnotcurses-sys/src/cells.rs b/rust/libnotcurses-sys/src/cells.rs index af0a5906e..f7309f3df 100644 --- a/rust/libnotcurses-sys/src/cells.rs +++ b/rust/libnotcurses-sys/src/cells.rs @@ -26,7 +26,7 @@ // - ? gcluster (&str) > type alias? // - ? attr (u32) > type alias? -use std::ffi::CString; +use cstr_core::CString; use crate as ffi; use crate::types::{ChannelPair, IntResult}; @@ -101,7 +101,6 @@ pub fn cells_load_box( // return -1; // } - // static inline void // cell_init(cell* c){ // memset(c, 0, sizeof(*c)); diff --git a/rust/libnotcurses-sys/src/lib.rs b/rust/libnotcurses-sys/src/lib.rs index 88d90a3b5..cd278ffd2 100644 --- a/rust/libnotcurses-sys/src/lib.rs +++ b/rust/libnotcurses-sys/src/lib.rs @@ -1,6 +1,7 @@ #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] +#![no_std] mod cells; mod channels; @@ -15,9 +16,10 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs")); #[cfg(test)] mod tests { - use std::ffi::{CStr, CString}; - use std::ptr::{null, null_mut}; + use core::ptr::{null, null_mut}; + use cstr_core::{CStr, CString}; + use libc_print::*; use serial_test::serial; // serialize tests w/ ffi::notcurses_init() use crate as ffi; @@ -31,7 +33,7 @@ mod tests { CStr::from_ptr(s) }; let r_str = c_str.to_str().unwrap(); - println!("rust-bound notcurses v{}", r_str); + libc_println!("rust-bound notcurses v{}", r_str); } #[test] diff --git a/rust/libnotcurses-sys/src/plane.rs b/rust/libnotcurses-sys/src/plane.rs index fdfc82d55..a7719b58a 100644 --- a/rust/libnotcurses-sys/src/plane.rs +++ b/rust/libnotcurses-sys/src/plane.rs @@ -5,8 +5,8 @@ // - ncplane_dim_x // - ncplane_perimeter -use std::ffi::CString; -use std::ptr::null_mut; +use core::ptr::null_mut; +use cstr_core::CString; use crate as ffi; use ffi::types::IntResult;