FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add a C API by lemire · Pull Request #897 · simdutf/simdutf · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension .c  (2) .cpp  (3) .h  (2) .md  (2) .py  (1) .sh  (1) .txt  (2) .yml  (6) All 8 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
34 changes: 34 additions & 0 deletions .github/workflows/amalgamation_demos.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: amalgamation demos

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
c++ amalgamation:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: C++ amalgamation demo
run: |
cd singleheader
./amalgamate.py
c++ -o amalgamation_demo amalgamation_demo.cpp -std=c++17
./amalgamation_demo

c amalgamation:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: c amalgamation demo
run: |
cd singleheader
./amalgamate.py
c++ -c simdutf.cpp
cc -c ./amalgamation_demo.c
c++ amalgamation_demo.o simdutf.o -o cdemo
./cdemo
2 changes: 2 additions & 0 deletions .github/workflows/debian-latestcxxstandards.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
matrix:
compiler: [g++-15, clang++-21]
cppversion: [26,]
cversion: [23,]
steps:
- uses: actions/checkout@v4
- name: install
Expand All @@ -28,6 +29,7 @@ jobs:
cmake \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
-DSIMDUTF_CXX_STANDARD=${{matrix.cppversion}} \
-DSIMDUTF_C_STANDARD=${{matrix.cversion}} \
-DSIMDUTF_BENCHMARKS=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DSIMDUTF_FAST_TESTS=On \
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/rvv-1024-clang-18.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ jobs:
sudo apt-get install -y cmake make g++-riscv64-linux-gnu qemu-user-static clang-18
- name: Build
run: |
CXX=clang++-18 CXXFLAGS="--target=riscv64-linux-gnu -march=rv64gcv_zvbb" \
cmake --toolchain=cmake/toolchains-ci/riscv64-linux-gnu.cmake -DCMAKE_BUILD_TYPE=Release -B build -DSIMDUTF_FAST_TESTS=On
CXX=clang++-18 \
CC=clang-18 \
CFLAGS="--target=riscv64-linux-gnu -march=rv64gcv_zvbb" \
CXXFLAGS="--target=riscv64-linux-gnu -march=rv64gcv_zvbb" \
cmake --toolchain=cmake/toolchains-ci/riscv64-linux-gnu.cmake \
-DCMAKE_BUILD_TYPE=Release \
-B build \
-DSIMDUTF_FAST_TESTS=On
cmake --build build/ -j$(nproc)
- name: Test VLEN=1024
run: |
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/rvv-128-clang-17.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ jobs:
sudo apt-get install -y cmake make g++-riscv64-linux-gnu qemu-user-static clang-17
- name: Build
run: |
CXX=clang++-17 CXXFLAGS="--target=riscv64-linux-gnu -march=rv64gcv" \
cmake --toolchain=cmake/toolchains-ci/riscv64-linux-gnu.cmake -DCMAKE_BUILD_TYPE=Release -B build -DSIMDUTF_FAST_TESTS=On
CXX=clang++-17 \
CC=clang-17 \
CFLAGS="--target=riscv64-linux-gnu -march=rv64gcv" \
CXXFLAGS="--target=riscv64-linux-gnu -march=rv64gcv" \
cmake --toolchain=cmake/toolchains-ci/riscv64-linux-gnu.cmake \
-DCMAKE_BUILD_TYPE=Release \
-B build \
-DSIMDUTF_FAST_TESTS=On
cmake --build build/ -j$(nproc)
- name: Test VLEN=128
run: |
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/rvv-256-gcc-14.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jobs:
sudo apt-get install -y cmake make g++-14-riscv64-linux-gnu qemu-user-static
- name: Build
run: |
CXX=riscv64-linux-gnu-g++-14 CXXFLAGS=-march=rv64gcv \
CXX=riscv64-linux-gnu-g++-14 \
CC=riscv64-linux-gnu-gcc-14 \
CXXFLAGS=-march=rv64gcv \
cmake --toolchain=cmake/toolchains-ci/riscv64-linux-gnu.cmake -DCMAKE_BUILD_TYPE=Release -B build -DSIMDUTF_FAST_TESTS=On
cmake --build build/ -j$(nproc)
- name: Test VLEN=256
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ubuntu24-cxxstandards.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ jobs:
matrix:
compiler: [g++-14, clang++-18]
cppversion: [11, 14, 17, 20, 23]
cversion: [11,]
steps:
- uses: actions/checkout@v4
- name: Build and test ${{matrix.compiler}} C++ ${{matrix.cppversion}}
run: |
cmake \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
-DSIMDUTF_CXX_STANDARD=${{matrix.cppversion}} \
-DSIMDUTF_C_STANDARD=${{matrix.cversion}} \
-DSIMDUTF_BENCHMARKS=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DSIMDUTF_FAST_TESTS=On \
Expand Down
9 changes: 8 additions & 1 deletion CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)

project(simdutf
DESCRIPTION "Fast Unicode validation, transcoding and processing"
LANGUAGES CXX
LANGUAGES C CXX
VERSION 7.7.1
)

Expand Down Expand Up @@ -105,6 +105,13 @@ install(
COMPONENT simdutf_Development
)


install(
FILES include/simdutf_c.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT simdutf_Development
)

install(
DIRECTORY include/simdutf
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
Expand Down
27 changes: 25 additions & 2 deletions README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2689,11 +2689,34 @@ If you use this library in your research, please cite our work:
```


Stars
-------

C wrapper (C11 or better)
Comment thread
pauldreik marked this conversation as resolved.
---------

*This is currently experimental. We are committed to maintaining the C API but there might be issues with
our implementation.*

We provide a thin C API that wraps the C++ `simdutf` library. It is intended
for applications that prefer or require a plain C interface. The `simdutf_c.h`
defines the interface.


The C API exposes functions for validation, transcoding, size estimation, `find` helpers,
and Base64 encode/decode helpers. Results are returned using the `simdutf_result` struct
which contains an `error_code` field and additional fields when relevant.


We provide a simple C demo using the C wrapper at `amalgamation_demo.c`.
It shows validating UTF-8, converting UTF-8 to UTF-16LE and back, and checking the round-trip.
Refer to `singleheader/README.md` for instructions. Note that the simdutf library requires
a C++ standard library (e.g., libstdc++, libc++) at runtime, either statically or dynamically linked.

Note: The C API is currently not aware of amalgamation with limited features. It expects the full simdutf library.


Stars
-------

[![Star History Chart](https://api.star-history.com/svg?repos=simdutf/simdutf&type=Date)](https://www.star-history.com/#simdutf/simdutf&Date)

License
Expand Down
Loading
Loading

Back | FazBrowse Home | New Git URL