-
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
Building as shared library #345
Comments
Hi @kpcyrd
So far there hasn't been explicit support for building a dynamic library (see this comment from Jsha for the rationale). It sounds like it's workable with the yet-to-be-merged cargo-c workflow, but isn't something that's tested+supported outright. |
I see, thanks for clarifying! |
If you're feeling brave testing+feedback about using rustls-ffi as a .so would be helpful input :-) |
I've used the patch from #274 and created this PKGBUILD: # Maintainer: kpcyrd <kpcyrd[at]archlinux[dot]org>
pkgname=librustls
pkgver=0.11.0
pkgrel=1
pkgdesc="Use rustls from languages other than Rust"
arch=('x86_64')
license=('Apache-2.0' 'MIT')
url='https://github.com/rustls/rustls-ffi'
makedepends=(
cargo-c
rust
)
provides=('librustls.so')
options=(!lto)
source=(https://github.com/rustls/rustls-ffi/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz
Cargo.lock
shared-linking.patch)
sha256sums=('0eeac3b916286cce35a3f32f3fd11f54ad2584a32bb67ac41c0c563c7c62c98b'
'06d3b4df897c45a3320e73dca2fcea1cde75f29b1c0a90f4930b403c7c7dc3b1'
'194e5df9f9ea87c53ac39e055ef2a4186ce93c8a50e03566b3947ab05423916b')
prepare() {
cd rustls-ffi-${pkgver}
cp ../Cargo.lock .
cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
patch -Np1 -i ../shared-linking.patch
}
updlockfiles() {
cd rustls-ffi-${pkgver}
rm -f Cargo.lock
cargo update
cp Cargo.lock "${outdir}/"
}
build() {
cd rustls-ffi-${pkgver}
RUSTC_BOOTSTRAP=1 cargo cbuild --release --frozen --prefix=/usr
}
package() {
cd rustls-ffi-${pkgver}
cargo cinstall --release --frozen --prefix /usr --destdir "${pkgdir}"
install -Dm644 -t "${pkgdir}/usr/share/licenses/${pkgname}" LICENSE-*
}
# vim: ts=2 sw=2 et: shared-linking.patch: From 5d0b71b045ce7f0a9a51e52d8d58ced622c914c2 Mon Sep 17 00:00:00 2001
From: Luca Barbato <[email protected]>
Date: Sat, 10 Dec 2022 12:00:41 +0100
Subject: [PATCH 1/3] Move the language configuration to cbindgen.toml
---
Makefile | 2 +-
cbindgen.toml | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index def7bf37..367e8426 100644
--- a/Makefile
+++ b/Makefile
@@ -38,7 +38,7 @@ target:
mkdir -p $@
src/rustls.h: src/*.rs cbindgen.toml
- cbindgen --lang C > $@
+ cbindgen > $@
target/$(PROFILE)/librustls_ffi.a: src/*.rs Cargo.toml
RUSTFLAGS="-C metadata=rustls-ffi" ${CARGO} build $(CARGOFLAGS)
diff --git a/cbindgen.toml b/cbindgen.toml
index 1a1b977a..335688d7 100644
--- a/cbindgen.toml
+++ b/cbindgen.toml
@@ -1,4 +1,5 @@
include_guard = "RUSTLS_H"
+language = "C"
usize_is_size_t = true
From cd2544a72ff4415196389b9e3014edb77a3634d3 Mon Sep 17 00:00:00 2001
From: Luca Barbato <[email protected]>
Date: Sat, 10 Dec 2022 12:29:23 +0100
Subject: [PATCH 2/3] Initial cargo-c support
---
Cargo.toml | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/Cargo.toml b/Cargo.toml
index 960e281e..d6bcf47a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,6 +20,7 @@ rust-version = "1.60"
# libraries.
no_log_capture = []
read_buf = ["rustls/read_buf"]
+capi = []
[dependencies]
# Keep in sync with RUSTLS_CRATE_VERSION in build.rs
@@ -33,3 +34,15 @@ log = "0.4.17"
[lib]
name = "rustls_ffi"
crate-type = ["lib", "staticlib"]
+
+[package.metadata.capi.header]
+name = "rustls"
+subdirectory = false
+
+[package.metadata.capi.library]
+name = "rustls"
+rustflags = "-Cmetadata=rustls-ffi"
+
+[package.metadata.capi.pkg_config]
+name = "rustls"
+filename = "rustls" The I also noticed
I couldn't figure out where that's coming from though. The PKGBUILD generates a package named
With this package installed it's now trivially possible to build curl like this:
badssl.com tests
|
|
With librustls 0.12.1 and without
|
@kpcyrd I think that's to be expected and the comment from Kangie wasn't saying that the nightly compiler isn't required anymore, but was explaining why it was: we're using a |
That's correct (and also as a note to myself at around midnight!) Is there an alternative that makes it possible to avoid the use of nightly features? I'm happy to have a go at making any required changes, I just don't know where to start! Over in Gentoo land, we can't rely on a nightly compiler being available; we need to compile rustls with whatever has been installed by the system package manager. This upstream issue with cbindgen seems related: |
Would you mind opening a separate issue to chat through this? It would also be helpful to know more about how you're building (e.g. are you using cargo-c?). There are probably options to look at.
We vendor the cbindgen generated rustls.h in-repo, which would avoid needing |
Arch Linux also doesn't use a nightly compiler, instead the system-wide compiler at Since librustls is now in Arch Linux with no further patches (and also curl-rustls to exercise the library) I think it's time to close this issue. Thanks everybody! |
Hello!
I've started looking into this repository while trying to build curl using
--with-rustls
, and getting this error:I've attempted to build a
librustls
package out of rustls-ffi but noticed it only contains an.a
file:Is there a way to build a .so file instead?
Thanks!
The text was updated successfully, but these errors were encountered: