fix(rust): use core crates for no_std

also add `no_std` build to CI
This commit is contained in:
Simon Willshire 2025-03-25 14:30:32 +01:00 committed by Christian Clason
parent acc9cafc7c
commit ed69a74463
3 changed files with 14 additions and 3 deletions

View file

@ -195,6 +195,13 @@ jobs:
npm run build
npm run build:debug
- name: Check no_std builds
if: ${{ !matrix.no-run && inputs.run-test }}
shell: bash
run: |
cd lib
$BUILD_CMD check --no-default-features
- name: Build target
run: $BUILD_CMD build --release --target=${{ matrix.target }} --features=${{ matrix.features }}

View file

@ -16,6 +16,7 @@ extern "C" {
}
#[cfg(windows)]
#[cfg(feature = "std")]
extern "C" {
pub(crate) fn _ts_dup(handle: *mut std::os::raw::c_void) -> std::os::raw::c_int;
}

View file

@ -1222,7 +1222,7 @@ impl Parser {
len: u32,
code_point: *mut i32,
) -> u32 {
let (c, len) = D::decode(std::slice::from_raw_parts(data, len as usize));
let (c, len) = D::decode(core::slice::from_raw_parts(data, len as usize));
if let Some(code_point) = code_point.as_mut() {
*code_point = c;
}
@ -1422,7 +1422,7 @@ impl Parser {
if let Some(flag) = flag {
ffi::ts_parser_set_cancellation_flag(
self.0.as_ptr(),
std::ptr::from_ref::<AtomicUsize>(flag).cast::<usize>(),
core::ptr::from_ref::<AtomicUsize>(flag).cast::<usize>(),
);
} else {
ffi::ts_parser_set_cancellation_flag(self.0.as_ptr(), ptr::null());
@ -1432,7 +1432,10 @@ impl Parser {
impl Drop for Parser {
fn drop(&mut self) {
self.stop_printing_dot_graphs();
#[cfg(feature = "std")]
{
self.stop_printing_dot_graphs();
}
self.set_logger(None);
unsafe { ffi::ts_parser_delete(self.0.as_ptr()) }
}