# cmp_rs
ESP-IDF prebuilt component shipping a self-contained Rust staticlib that
exposes a single C-ABI function, `rust_ascii_convert`. The C source used
internally is compiled into the `.a` at Rust build time via the `cc` crate,
so this component has no source files of its own — only a header and the
prebuilt archive ship.
## Layout
```
cmp_rs/
├── CMakeLists.txt
├── idf_component.yml
├── LICENSE
├── README.md
├── include/
│ └── cmp_rs.h
└── lib/
└── esp32s3/
└── libascii_rs.a
```
To support additional chips, rebuild the Rust project for each target and
drop the resulting `.a` under `lib/<idf_target>/libascii_rs.a`. The
`CMakeLists.txt` selects the right archive automatically based on
`IDF_TARGET`.
## Usage
In a consuming ESP-IDF project, add to `main/idf_component.yml`:
```yaml
dependencies:
jays0223/cmp_rs: "^0.1.0"
```
Then call it:
```c
#include <stdint.h>
#include <string.h>
#include "cmp_rs.h"
void app_main(void) {
const char *msg = "Hello";
uint8_t out[16];
rust_ascii_convert(msg, out, strlen(msg));
// out == { 72, 101, 108, 108, 111 }
}
```
## Rebuilding the staticlib
```sh
cd /path/to/esp32s3-ascii
cargo build --release
cp target/xtensa-esp32s3-espidf/release/libascii_rs.a \
/path/to/cmp_rs/lib/esp32s3/
```
## Publishing
```sh
pip install idf-component-manager
export IDF_COMPONENT_API_TOKEN=<token-from-components.espressif.com>
cd /Users/karanrajput/esp-rs/cmp_rs
compote component upload --namespace jays0223 --name cmp_rs
```
idf.py add-dependency "jays0223/cmp_rs^0.0.9"