-
-
Notifications
You must be signed in to change notification settings - Fork 22
Add the metadata needed by cargo-c #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e312a44
2cf226b
e7fca91
7723ebc
b3ea962
e7d03c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ Build `zlib-rs` as a drop-in replacement for the zlib dynamic library | |
|
||
```sh | ||
# build the cdylib | ||
# using `cargo build` will work but has limitations, see below | ||
cargo build --release | ||
|
||
# the extension of a cdylib varies per platform | ||
|
@@ -14,8 +15,9 @@ cc zpipe.c target/release/libz_rs.so | |
``` | ||
|
||
By default this build uses libc `malloc`/`free` to (de)allocate memory, and only depends on the rust `core` library. | ||
See below for the available feature flags. | ||
|
||
## Features | ||
## Feature Flags | ||
|
||
### Allocators | ||
|
||
|
@@ -74,6 +76,39 @@ the standard library has the following limitations: | |
|
||
- CPU feature detection is currently disabled. This is true for both compile-time and run-time feature detection. | ||
This means `zlib-rs` will not make use of SIMD or other custom instructions. | ||
- The `rust-allocator` should not be used. It internally enables the standard library, causing issues. Using `c-allocator` | ||
or not providing an allocator at build time is still supported.On embedded it is most common to provide a custom allocator | ||
- The `rust-allocator` should not be used. It internally enables the standard library, causing issues. Using `c-allocator` | ||
or not providing an allocator at build time is still supported.On embedded it is most common to provide a custom allocator | ||
that "allocates" into a custom array. | ||
|
||
## Build for Distribution | ||
|
||
A `cargo build` currently does not set some fields that are required or useful when using a dynamic library from C. | ||
For instance, the soname and version are not set by a standard `cargo build`. | ||
|
||
To build a proper, installable dynamic library, we recommend [`cargo-c`](https://github.com/lu-zero/cargo-c): | ||
|
||
``` | ||
cargo install cargo-c | ||
``` | ||
|
||
This tool deals with setting fields (soname, version) that a normal `cargo build` does not set (today). | ||
It's configuration is in the `Cargo.toml`, where e.g. the library name or version can be changed. | ||
|
||
``` | ||
> cargo cbuild --release | ||
Compiling zlib-rs v0.2.1 | ||
Compiling libz-rs-sys v0.2.1 | ||
Compiling libz-rs-sys-cdylib v0.2.1 | ||
Finished `release` profile [optimized] target(s) in 1.86s | ||
Building pkg-config files | ||
> tree target | ||
target | ||
├── CACHEDIR.TAG | ||
└── x86_64-unknown-linux-gnu | ||
└── release | ||
├── libz_rs.a | ||
├── libz_rs.d | ||
├── libz_rs.pc | ||
├── libz_rs.so | ||
└── libz_rs-uninstalled.pc | ||
Comment on lines
+104
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lu-zero is there a reason There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is required until cargo learns to differentiate the RUSTFLAGS for the build.rs and the RUSTFLAGS for the host. using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you aware of a cargo issue that describes the problem? I'll be meeting with some members of the cargo team in October, and I'd like to prepare some concrete things to make progress on. Given how crucial this is for sneaking rust into C code bases I think progress can be made. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rust-lang/cargo#4423 is another way to see the problem and rust-lang/cargo#9452 is how to solve it. But normally I guess I should really prepare a blogpost showing how to use cargo-c in many deployment scenarios :) |
||
``` |
Uh oh!
There was an error while loading. Please reload this page.