-
Notifications
You must be signed in to change notification settings - Fork 30
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
cargo-c support #274
Merged
Merged
cargo-c support #274
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,23 +20,37 @@ to provide the cryptographic primitives. | |||||||||
# Build | ||||||||||
|
||||||||||
You'll need to [install the Rust toolchain](https://rustup.rs/) (version 1.61 | ||||||||||
or above) and a C compiler (`gcc` and `clang` should both work). To build in optimized mode: | ||||||||||
or above) and a C compiler (`gcc` and `clang` should both work). | ||||||||||
|
||||||||||
## Static Library | ||||||||||
|
||||||||||
In its current for rustls-ffi's `Makefile` infrastructure will generate a static | ||||||||||
system library (e.g. `--crate-type=staticlib`), producing a `.a` or `.lib` file | ||||||||||
(depending on the OS). | ||||||||||
|
||||||||||
We recommend using rustls-ffi as a static library as we make no guarantees of | ||||||||||
[ABI](https://en.wikipedia.org/wiki/Application_binary_interface) stability across | ||||||||||
versions at this time, and dynamic library support is considered **experimental**. | ||||||||||
|
||||||||||
### Building a Static Library | ||||||||||
|
||||||||||
To build a static library in optimized mode: | ||||||||||
|
||||||||||
make | ||||||||||
|
||||||||||
To install in `/usr/local/`: | ||||||||||
|
||||||||||
sudo make install | ||||||||||
|
||||||||||
To build in debug mode: | ||||||||||
To build a static library in debug mode: | ||||||||||
|
||||||||||
make PROFILE=debug | ||||||||||
|
||||||||||
To link against the resulting library, on **Linux**: | ||||||||||
To link against the resulting static library, on **Linux**: | ||||||||||
|
||||||||||
-lrustls -lgcc_s -lutil -lrt -lpthread -lm -ldl -lc | ||||||||||
|
||||||||||
To link against the resulting library, on **macOS**: | ||||||||||
To link against the resulting static library, on **macOS**: | ||||||||||
|
||||||||||
-lrustls -framework Security -liconv -lSystem -lc -l | ||||||||||
|
||||||||||
|
@@ -45,6 +59,60 @@ via](https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-c | |||||||||
|
||||||||||
RUSTFLAGS="--print native-static-libs" cargo build | ||||||||||
|
||||||||||
## Dynamic Library | ||||||||||
|
||||||||||
Using rustls-ffi as a static library has some downsides. Notably each application | ||||||||||
that links the static library will need to be rebuilt for each update to rustls-ffi, | ||||||||||
and duplicated copies of rustls-ffi will be included in each application. | ||||||||||
|
||||||||||
Building rustls-ffi as a dynamic library (`--crate-type=cdylib`) can resolve these | ||||||||||
issues, however this approach comes with its own trade-offs. We currently consider | ||||||||||
this option **experimental**. | ||||||||||
|
||||||||||
### ABI Stability | ||||||||||
|
||||||||||
At this time rustls-ffi makes **no** guarantees about | ||||||||||
[ABI](https://en.wikipedia.org/wiki/Application_binary_interface) stability. | ||||||||||
Each release of rustls-ffi may introduce breaking changes to the ABI and so | ||||||||||
the built library should use the exact rustls-ffi version as the dynamic library | ||||||||||
[SONAME](https://en.wikipedia.org/wiki/Soname). | ||||||||||
|
||||||||||
### Building a Dynamic Library | ||||||||||
|
||||||||||
Since building a useful dynamic library is more complex than building a static | ||||||||||
library, rustls-ffi uses [cargo-ci](https://github.com/lu-zero/cargo-c) in place | ||||||||||
of the `Makefile` system used for the static library. | ||||||||||
|
||||||||||
This takes care of: | ||||||||||
* Generating the `rustls.h` header file. | ||||||||||
* Building a `.so` or `.dylib` file (depending on the OS). | ||||||||||
* Generating a [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) `.pc` file. | ||||||||||
* Installing the library and header files in the appropriate location. | ||||||||||
|
||||||||||
If your operating system doesn't package `cargo-c` natively | ||||||||||
(see [package availability](https://github.com/lu-zero/cargo-c#availability)), | ||||||||||
you can install it with: | ||||||||||
|
||||||||||
cargo install cargo-c | ||||||||||
|
||||||||||
To build a dynamic library in optimized mode: | ||||||||||
|
||||||||||
cargo capi build --release | ||||||||||
|
||||||||||
To install in `/usr/local/`: | ||||||||||
|
||||||||||
sudo cargo capi install | ||||||||||
|
||||||||||
To build a static library in debug mode: | ||||||||||
|
||||||||||
cargo capi build | ||||||||||
|
||||||||||
To link against the resulting dynamic library, use `pkg-config` to populate your | ||||||||||
`LDLIBS` and `CFLAGS` as appropriate: | ||||||||||
|
||||||||||
pkg-config --libs rustls | ||||||||||
pkg-config --cflags rustls | ||||||||||
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. Nit: this seems to suggest that these
Suggested change
|
||||||||||
|
||||||||||
# Overview | ||||||||||
|
||||||||||
Rustls doesn't do any I/O on its own. It provides the protocol handling, and | ||||||||||
|
This file contains 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
include_guard = "RUSTLS_H" | ||
language = "C" | ||
|
||
usize_is_size_t = true | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.