NSTD

A cross-platform, fast, and safe general purpose C library written in Rust.

The library is organized as a series of modules. The top level module nstd encompasses the entire crate. Each module can have their own submodules (eg. nstd.io.stdout or nstd::io::stdout with Rust syntax).

Example using C

```c // Build nstd with features set to "capi nstdcore nstdio".

include

/// Main entry point of the program. int main() { const NSTDStr output = nstdcorestrfromrawcstr("Hello, 🌎!"); nstdioprintline(&output); return 0; } ```

Library modules

Platform support

nstd.core should support anything that rustc supports.

nstd.os's child modules will only work on the operating system they target. For example, nstd.os.windows will only work on Windows and nstd.os.unix will only work on Unix-like systems.

Other modules will work on most platforms, primarily targeting Windows, macOS, Linux, Android, and iOS.

Language support

This library can be accessed from any language that supports calling C code. As of now this will need to be done manually as there are no official wrappers for the API, however somewhere around version 0.11, the plan is to start adding official wrappers so developers from other languages can easily use the API.

Safety

Please note that these safety notes (as well as the framework as a whole) are a work in progress.

User safety notes

Contributor safety notes

How to build

Building nstd as a C library requires you to specify the "crate-type" manually. To do this you must pass a --crate-type of either cdylib or staticlib to rustc. Rust allows you to use this flag multiple times in case you need both.

nstd lets you decide what features you want to use.

Any module that falls under the top level module has a dedicated feature flag, for example nstd.core has the feature flag nstd_core and nstd.alloc has the feature flag nstd_alloc.

Each module may have additional features, for example nstd.os has the additional nstd_os_windows_alloc feature for memory allocation on Windows, this allows other modules to use the low level memory allocation API for Windows without enabling memory allocation for other operating systems.

The capi feature flag is used to build nstd as a C library.

The std feature flag links the Rust standard library into the binary.

The asm feature permits the library to use assembly to optimize certain build configurations.

std and nstd_core are enabled by default.

Example: sh cargo rustc --release --crate-type cdylib --crate-type staticlib --features "capi nstd_alloc"

To build with all features: sh cargo rustc --release --crate-type cdylib --crate-type staticlib --all-features

Installing with cargo-c

nstd also allows you to use cargo-c to build or install the library.

Install cargo-c: sh cargo install cargo-c

Here is an example of how to build the library for a Unix machine with all features enabled: sh cargo cinstall --release --all-features --destdir=./install --prefix=/usr --libdir=/usr/lib This will create a new install directory with the installation contents.

You can now copy the contents to the root folder using cp: sh sudo cp -a ./install/* /

More information can be found in the cargo-c repo and in this blog post by Luca Barbato.

Releases

nstd versions follow the Semantic Versioning rules. Each release is given a major, minor, and patch number that makes up that version of the library (major.minor.patch).

There have not yet been any major releases for the framework as it is not yet stable.

A new minor version is released every 6 weeks, exactly 1 week after a new minor Rust release.

Patch releases are released every so often with minor fixes and additions.

See semver.org to learn more about Semantic Versioning.