This repository was archived by the owner on Mar 23, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +50
-3
lines changed Expand file tree Collapse file tree 7 files changed +50
-3
lines changed Original file line number Diff line number Diff line change 18
18
command : check
19
19
args : --tests
20
20
21
+ build_no_std :
22
+ name : Build on no_std
23
+ runs-on : ubuntu-latest
24
+ steps :
25
+ - uses : actions/checkout@v2
26
+ - uses : actions-rs/toolchain@v1
27
+ with :
28
+ profile : minimal
29
+ toolchain : stable
30
+ target : thumbv7em-none-eabi
31
+ override : true
32
+ - uses : actions-rs/cargo@v1
33
+ with :
34
+ command : build
35
+ args : >-
36
+ --verbose
37
+ --target thumbv7em-none-eabi
38
+ --manifest-path tests/test_no_std/Cargo.toml
39
+
21
40
test :
22
41
name : Test Suite
23
42
runs-on : ubuntu-latest
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ license = "MIT"
8
8
keywords = [" macro" , " cstr" ]
9
9
readme = " README.md"
10
10
edition = " 2018"
11
+ rust-version = " 1.64"
11
12
12
13
[lib ]
13
14
proc-macro = true
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ A macro for getting `&'static CStr` from literal or identifier.
11
11
This macro checks whether the given literal is valid for ` CStr `
12
12
at compile time, and returns a static reference of ` CStr ` .
13
13
14
- This macro can be used to to initialize constants on Rust 1.59 and above.
14
+ This macro can be used to to initialize constants on Rust 1.64 and above.
15
15
16
16
## Example
17
17
Original file line number Diff line number Diff line change 3
3
//! This macro checks whether the given literal is valid for `CStr`
4
4
//! at compile time, and returns a static reference of `CStr`.
5
5
//!
6
- //! This macro can be used to to initialize constants on Rust 1.59 and above.
6
+ //! This macro can be used to to initialize constants on Rust 1.64 and above.
7
7
//!
8
8
//! ## Example
9
9
//!
@@ -37,7 +37,7 @@ struct Error(Span, &'static str);
37
37
#[ proc_macro]
38
38
pub fn cstr ( input : RawTokenStream ) -> RawTokenStream {
39
39
let tokens = match build_byte_str ( input. into ( ) ) {
40
- Ok ( s) => quote ! ( unsafe { :: std :: ffi:: CStr :: from_bytes_with_nul_unchecked( #s) } ) ,
40
+ Ok ( s) => quote ! ( unsafe { :: core :: ffi:: CStr :: from_bytes_with_nul_unchecked( #s) } ) ,
41
41
Err ( Error ( span, msg) ) => quote_spanned ! ( span => compile_error!( #msg) ) ,
42
42
} ;
43
43
tokens. into ( )
Original file line number Diff line number Diff line change
1
+ /target /
2
+ Cargo.lock
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " test_no_std"
3
+ version = " 0.0.0"
4
+ edition = " 2021"
5
+ license = " MIT"
6
+
7
+ publish = false
8
+
9
+ [dependencies ]
10
+ cstr.path = " ../../"
Original file line number Diff line number Diff line change
1
+ //! Verifies that cstr! can be used on no_std systems.
2
+ //!
3
+ //! To ensure that `std` is not sneaked in through a dependency (even though this crate has none at
4
+ //! runtime), this should best be built on a target that has no `std` because it has no operating
5
+ //! system, eg. thumbv7em-none-eabi.
6
+ //!
7
+ //! Note that building the [`cstr`] crate alone is insufficient, as it does not run throuogh any
8
+ //! `cstr!()` code generation and thus not trip over std-isms in the generated code.
9
+ #![ no_std]
10
+
11
+ use core:: ffi:: CStr ;
12
+
13
+ pub fn can_use_cstr_macro ( ) -> & ' static CStr {
14
+ cstr:: cstr!( "Hello World!" )
15
+ }
You can’t perform that action at this time.
0 commit comments