Skip to content

Commit 6841f3f

Browse files
committed
Fix build
1 parent 20eeba2 commit 6841f3f

6 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎.github/workflows/test_cli.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,8 @@ jobs:
4949
- name: Lint with Clippy
5050
run: cargo clippy -- -D warnings
5151

52+
- name: Lint with Clippy (C API)
53+
run: cargo clippy --features c-api -- -D warnings
54+
5255
# - name: Cargo Test
5356
# run: cargo test

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ crate-type = ["cdylib", "staticlib", "rlib"]
2424
default = ["wasm-api"]
2525
std = []
2626
wasm-api = ["std"]
27+
c-api = []

‎examples/c_api/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ message(STATUS "Looking for library in ${LIB_DIR}")
1818
find_library(SEA_LIB NAMES sea_codec libsea_codec sea_codec.dll PATHS ${LIB_DIR} NO_DEFAULT_PATH)
1919

2020
if(NOT SEA_LIB)
21-
message(WARNING "sea-codec library not found in ${LIB_DIR}. Please build the rust project first (cargo build).")
21+
message(WARNING "sea-codec library not found in ${LIB_DIR}. Please build the rust project first (cargo build --features c-api).")
2222
endif()
2323

2424
add_executable(c_example main.c)

‎examples/c_api/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ To build a static library for a different platform (e.g., ARM Cortex-M3), use `r
5858

5959
```sh
6060
rustup target add thumbv7m-none-eabi
61-
cargo build --release --target thumbv7m-none-eabi
61+
cargo build --release --target thumbv7m-none-eabi --features c-api
6262
```

‎src/c_api.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ pub extern "C" fn sea_encoder_default_settings() -> CSeaEncoderSettings {
3939
}
4040

4141
#[no_mangle]
42+
/// # Safety
43+
///
44+
/// * `input_samples` must be a valid pointer to an array of `i16` of length `input_length`.
45+
/// * `output_data` must be a valid pointer to a pointer where the output buffer address will be stored.
46+
/// * `output_length` must be a valid pointer where the output length will be stored.
47+
/// * If `settings` is not null, it must point to a valid `CSeaEncoderSettings` struct.
4248
pub unsafe extern "C" fn sea_encode(
4349
input_samples: *const i16,
4450
input_length: usize,
@@ -73,6 +79,12 @@ pub unsafe extern "C" fn sea_encode(
7379
}
7480

7581
#[no_mangle]
82+
/// # Safety
83+
///
84+
/// * `encoded_data` must be a valid pointer to a byte array of length `encoded_length`.
85+
/// * `output_samples` must be a valid pointer to a pointer where the decoded samples address will be stored.
86+
/// * `output_sample_count` must be a valid pointer where the sample count will be stored.
87+
/// * `output_sample_rate` and `output_channels` may be null, but if provided must be valid pointers.
7688
pub unsafe extern "C" fn sea_decode(
7789
encoded_data: *const u8,
7890
encoded_length: usize,
@@ -109,13 +121,21 @@ pub unsafe extern "C" fn sea_decode(
109121
}
110122

111123
#[no_mangle]
124+
/// # Safety
125+
///
126+
/// * `data` must be a pointer to a memory block allocated by `sea_encode` (or compatible Rust allocator).
127+
/// * `length` must match the length of the allocated block.
112128
pub unsafe extern "C" fn sea_free_packet(data: *mut u8, length: usize) {
113129
if !data.is_null() {
114130
let _ = Vec::from_raw_parts(data, length, length);
115131
}
116132
}
117133

118134
#[no_mangle]
135+
/// # Safety
136+
///
137+
/// * `samples` must be a pointer to a memory block allocated by `sea_decode` (or compatible Rust allocator).
138+
/// * `length` must match the length of the allocated block.
119139
pub unsafe extern "C" fn sea_free_samples(samples: *mut i16, length: usize) {
120140
if !samples.is_null() {
121141
let _ = Vec::from_raw_parts(samples, length, length);

‎src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub mod encoder;
1313
#[cfg(all(target_arch = "wasm32", feature = "wasm-api"))]
1414
pub mod wasm_api;
1515

16+
#[cfg(feature = "c-api")]
1617
pub mod c_api;
1718

1819
pub fn sea_encode(

0 commit comments

Comments
 (0)