Skip to content
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

Closed
kpcyrd opened this issue Sep 24, 2023 · 10 comments
Closed

Building as shared library #345

kpcyrd opened this issue Sep 24, 2023 · 10 comments

Comments

@kpcyrd
Copy link
Contributor

kpcyrd commented Sep 24, 2023

Hello!

I've started looking into this repository while trying to build curl using --with-rustls, and getting this error:

configure: error: --with-rustls was specified but could not find rustls.

I've attempted to build a librustls package out of rustls-ffi but noticed it only contains an .a file:

drwxr-xr-x root/root         0 2023-09-24 21:07 usr/
drwxr-xr-x root/root         0 2023-09-24 21:07 usr/include/
-rwxr-xr-x root/root     79764 2023-09-24 21:07 usr/include/rustls.h
drwxr-xr-x root/root         0 2023-09-24 21:07 usr/lib/
-rwxr-xr-x root/root  30385654 2023-09-24 21:07 usr/lib/librustls.a

Is there a way to build a .so file instead?

Thanks!

@cpu
Copy link
Member

cpu commented Sep 26, 2023

Hi @kpcyrd

Is there a way to build a .so file instead?

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.

@kpcyrd
Copy link
Contributor Author

kpcyrd commented Sep 27, 2023

I see, thanks for clarifying!

@cpu
Copy link
Member

cpu commented Sep 27, 2023

If you're feeling brave testing+feedback about using rustls-ffi as a .so would be helpful input :-)

@kpcyrd
Copy link
Contributor Author

kpcyrd commented Sep 27, 2023

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 updlockfiles() is a non-standard extension for reproducible builds since the Cargo.lock is currently not tracked in git (I could drop this if the release would contain an official Cargo.lock). Some Rust libraries that are only consumed by cargo often don't have one, but since this repository is for a binary artifact it would be useful to have one. :)

I also noticed RUSTC_BOOTSTRAP=1 is necessary because something is running this command (and invoking nightly features with -Zunpretty=expanded):

rustc --crate-name rustls_ffi --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --crate-type staticlib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -Zunpretty=expanded --cfg 'feature=\"read_buf\"' -C metadata=eb8220a1b1cf151e -C extra-filename=-eb8220a1b1cf151e --out-dir /build/librustls/src/rustls-ffi-0.11.0/target/debug/deps -C incremental=/build/librustls/src/rustls-ffi-0.11.0/target/debug/incremental -L dependency=/build/librustls/src/rustls-ffi-0.11.0/target/debug/deps --extern libc=/build/librustls/src/rustls-ffi-0.11.0/target/debug/deps/liblibc-16eaff70b0c3f5ff.rmeta --extern log=/build/librustls/src/rustls-ffi-0.11.0/target/debug/deps/liblog-a87e8a6c953f9fb0.rmeta --extern rustls=/build/librustls/src/rustls-ffi-0.11.0/target/debug/deps/librustls-66235c2143483566.rmeta --extern rustls_pemfile=/build/librustls/src/rustls-ffi-0.11.0/target/debug/deps/librustls_pemfile-662beeafaa0ba36e.rmeta --extern webpki=/build/librustls/src/rustls-ffi-0.11.0/target/debug/deps/libwebpki-f5d52ca4e005d782.rmeta --extern sct=/build/librustls/src/rustls-ffi-0.11.0/target/debug/deps/libsct-15265ca806435f24.rmeta -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls -L native=/build/librustls/src/rustls-ffi-0.11.0/target/debug/build/ring-f6cc86ea89f5463a/out

I couldn't figure out where that's coming from though.

The PKGBUILD generates a package named librustls-0.11.0-1-x86_64.pkg.tar.zst:

% tar tvvf librustls-0.11.0-1-x86_64.pkg.tar.zst
-rw-r--r-- root/root      4847 2023-09-27 20:06 .BUILDINFO
-rw-r--r-- root/root       837 2023-09-27 20:06 .MTREE
-rw-r--r-- root/root       410 2023-09-27 20:06 .PKGINFO
drwxr-xr-x root/root         0 2023-09-27 20:06 usr/
drwxr-xr-x root/root         0 2023-09-27 20:06 usr/include/
-rw-r--r-- root/root     79837 2023-09-27 20:06 usr/include/rustls.h
drwxr-xr-x root/root         0 2023-09-27 20:06 usr/lib/
lrwxrwxrwx root/root         0 2023-09-27 20:06 usr/lib/librustls.so -> librustls.so.0.11.0
lrwxrwxrwx root/root         0 2023-09-27 20:06 usr/lib/librustls.so.0 -> librustls.so.0.11.0
-rwxr-xr-x root/root   1776024 2023-09-27 20:06 usr/lib/librustls.so.0.11.0
drwxr-xr-x root/root         0 2023-09-27 20:06 usr/lib/pkgconfig/
-rw-r--r-- root/root       280 2023-09-27 20:06 usr/lib/pkgconfig/rustls.pc
drwxr-xr-x root/root         0 2023-09-27 20:06 usr/share/
drwxr-xr-x root/root         0 2023-09-27 20:06 usr/share/licenses/
drwxr-xr-x root/root         0 2023-09-27 20:06 usr/share/licenses/librustls/
-rw-r--r-- root/root     10847 2023-09-27 20:06 usr/share/licenses/librustls/LICENSE-APACHE
-rw-r--r-- root/root       781 2023-09-27 20:06 usr/share/licenses/librustls/LICENSE-ISC
-rw-r--r-- root/root      1089 2023-09-27 20:06 usr/share/licenses/librustls/LICENSE-MIT

With this package installed it's now trivially possible to build curl like this:

./configure --with-rustls
make
% ./src/curl --version
curl 8.4.0-DEV (x86_64-pc-linux-gnu) libcurl/8.4.0-DEV rustls-ffi/0.11.0/rustls/0.21.5 zlib/1.3 brotli/1.1.0 zstd/1.5.5 libidn2/2.3.4 libpsl/0.21.2 (+libidn2/2.3.4) nghttp2/1.56.0 librtmp/2.3 OpenLDAP/2.6.6
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli HSTS HTTP2 HTTPS-proxy IDN IPv6 Largefile libz PSL SSL threadsafe UnixSockets zstd

badssl.com tests

% for x in expired wrong.host self-signed untrusted-root revoked dh480 dh512 dh1024 dh-small-subgroup dh-composite sha1-2017 sha1-intermediate invalid-expected-sct rc4-md5 rc4 3des null; do echo "[+] Testing $x..."; ./src/curl "https://$x.badssl.com"; done
[+] Testing expired...
curl: (60) rustls_connection_process_new_packets: invalid peer certificate: Expired
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
[+] Testing wrong.host...
curl: (60) rustls_connection_process_new_packets: invalid peer certificate: NotValidForName
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
[+] Testing self-signed...
curl: (60) rustls_connection_process_new_packets: invalid peer certificate: UnknownIssuer
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
[+] Testing untrusted-root...
curl: (60) rustls_connection_process_new_packets: invalid peer certificate: UnknownIssuer
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
[+] Testing revoked...
curl: (60) rustls_connection_process_new_packets: invalid peer certificate: Expired
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
[+] Testing dh480...
curl: (35) rustls_connection_process_new_packets: received fatal alert: HandshakeFailure
[+] Testing dh512...
curl: (35) rustls_connection_process_new_packets: received fatal alert: HandshakeFailure
[+] Testing dh1024...
curl: (35) rustls_connection_process_new_packets: received fatal alert: HandshakeFailure
[+] Testing dh-small-subgroup...
curl: (35) rustls_connection_process_new_packets: received fatal alert: HandshakeFailure
[+] Testing dh-composite...
curl: (35) rustls_connection_process_new_packets: received fatal alert: HandshakeFailure
[+] Testing sha1-2017...
curl: (60) rustls_connection_process_new_packets: invalid peer certificate: Expired
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
[+] Testing sha1-intermediate...
curl: (60) rustls_connection_process_new_packets: invalid peer certificate: Expired
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
[+] Testing invalid-expected-sct...
curl: (60) rustls_connection_process_new_packets: invalid peer certificate: Expired
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
[+] Testing rc4-md5...
curl: (35) rustls_connection_process_new_packets: received fatal alert: HandshakeFailure
[+] Testing rc4...
curl: (35) rustls_connection_process_new_packets: received fatal alert: HandshakeFailure
[+] Testing 3des...
curl: (35) rustls_connection_process_new_packets: received fatal alert: HandshakeFailure
[+] Testing null...
curl: (35) rustls_connection_process_new_packets: received fatal alert: HandshakeFailure

@Kangie
Copy link

Kangie commented Mar 27, 2024

I also noticed RUSTC_BOOTSTRAP=1 is necessary because something is running this command (and invoking nightly features with -Zunpretty=expanded):

b5fc7d1

@kpcyrd
Copy link
Contributor Author

kpcyrd commented Mar 27, 2024

With librustls 0.12.1 and without RUSTC_BOOTSTRAP=1 I'm still getting this:

==> Starting build()...
   Compiling libc v0.2.153
   Compiling cfg-if v1.0.0
   Compiling spin v0.9.8
   Compiling rustls-pki-types v1.3.1
   Compiling untrusted v0.9.0
   Compiling rustls v0.22.0
   Compiling subtle v2.5.0
   Compiling base64 v0.21.5
   Compiling log v0.4.21
   Compiling zeroize v1.7.0
   Compiling rustls-ffi v0.12.1 (/build/librustls/src/rustls-ffi-0.12.1)
   Compiling rustls-pemfile v2.1.1
   Compiling cc v1.0.83
   Compiling getrandom v0.2.11
   Compiling ring v0.17.5
   Compiling rustls-webpki v0.102.0
    Finished release [optimized] target(s) in 10.35s
    Building pkg-config files
    Building header file using cbindgen
thread 'main' panicked at src/build.rs:55:10:
called `Result::unwrap()` on an `Err` value: CargoExpand("rustls-ffi", Compile("   Compiling libc v0.2.153\n   Compiling rustversion v1.0.14\n    Checking cfg-if v1.0.0\n    Checking rustls-pki-types v1.3.1\n    Checking untrusted v0.9.0\n    Checking spin v0.9.8\n    Checking subtle v2.5.0\n    Checking zeroize v1.7.0\n    Checking base64 v0.21.5\n    Checking log v0.4.21\n   Compiling rustls-ffi v0.12.1 (/build/librustls/src/rustls-ffi-0.12.1)\n     Running `rustc --crate-name build_script_build /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.153/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C metadata=c90484cde5438962 -C extra-filename=-c90484cde5438962 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/build/libc-c90484cde5438962 -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `rustc --crate-name build_script_build /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.153/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no --cfg 'feature=\"default\"' --cfg 'feature=\"std\"' -C metadata=23831b7041c698f7 -C extra-filename=-23831b7041c698f7 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/build/libc-23831b7041c698f7 -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `rustc --crate-name build_script_build --edition=2018 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustversion-1.0.14/build/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C metadata=b6798236f6943cf3 -C extra-filename=-b6798236f6943cf3 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/build/rustversion-b6798236f6943cf3 -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `rustc --crate-name cfg_if --edition=2018 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cfg-if-1.0.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C metadata=419f92d015e31f97 -C extra-filename=-419f92d015e31f97 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `rustc --crate-name rustls_pki_types --edition=2021 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-pki-types-1.3.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 --cfg 'feature=\"alloc\"' --cfg 'feature=\"default\"' --cfg 'feature=\"std\"' -C metadata=c0b870f5fdf4ce28 -C extra-filename=-c0b870f5fdf4ce28 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `rustc --crate-name untrusted --edition=2018 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/untrusted-0.9.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C metadata=a33f9bdba118a386 -C extra-filename=-a33f9bdba118a386 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `rustc --crate-name spin /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/spin-0.9.8/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 --cfg 'feature=\"once\"' -C metadata=a35495af919d6a27 -C extra-filename=-a35495af919d6a27 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `rustc --crate-name subtle --edition=2018 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/subtle-2.5.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C metadata=f4be4d9978db3e65 -C extra-filename=-f4be4d9978db3e65 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `rustc --crate-name zeroize --edition=2021 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zeroize-1.7.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 --cfg 'feature=\"alloc\"' --cfg 'feature=\"default\"' -C metadata=aa51ad6cd7f42774 -C extra-filename=-aa51ad6cd7f42774 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `rustc --crate-name base64 --edition=2018 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/base64-0.21.5/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 --cfg 'feature=\"alloc\"' --cfg 'feature=\"std\"' -C metadata=3513083394d21570 -C extra-filename=-3513083394d21570 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `rustc --crate-name log --edition=2021 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/log-0.4.21/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C metadata=bc3412dfc1f9b890 -C extra-filename=-bc3412dfc1f9b890 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `rustc --crate-name build_script_build --edition=2021 build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no --cfg 'feature=\"read_buf\"' -C metadata=088214c81a4c048d -C extra-filename=-088214c81a4c048d --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/build/rustls-ffi-088214c81a4c048d -C incremental=/build/librustls/src/rustls-ffi-0.12.1/target/debug/incremental -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `/build/librustls/src/rustls-ffi-0.12.1/target/debug/build/rustls-ffi-088214c81a4c048d/build-script-build`\n    Checking rustls-pemfile v2.1.1\n     Running `rustc --crate-name rustls_pemfile --edition=2018 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-pemfile-2.1.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 --cfg 'feature=\"default\"' --cfg 'feature=\"std\"' -C metadata=1fa066e65a3c7932 -C extra-filename=-1fa066e65a3c7932 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --extern base64=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libbase64-3513083394d21570.rmeta --extern pki_types=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/librustls_pki_types-c0b870f5fdf4ce28.rmeta --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `/build/librustls/src/rustls-ffi-0.12.1/target/debug/build/libc-c90484cde5438962/build-script-build`\n     Running `/build/librustls/src/rustls-ffi-0.12.1/target/debug/build/libc-23831b7041c698f7/build-script-build`\n     Running `/build/librustls/src/rustls-ffi-0.12.1/target/debug/build/rustversion-b6798236f6943cf3/build-script-build`\n     Running `rustc --crate-name libc /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.153/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C metadata=9cfae217150302a9 -C extra-filename=-9cfae217150302a9 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls --cfg freebsd11 --cfg libc_priv_mod_use --cfg libc_union --cfg libc_const_size_of --cfg libc_align --cfg libc_int128 --cfg libc_core_cvoid --cfg libc_packedN --cfg libc_cfg_target_vendor --cfg libc_non_exhaustive --cfg libc_long_array --cfg libc_ptr_addr_of --cfg libc_underscore_const_names --cfg libc_const_extern_fn`\n     Running `rustc --crate-name libc /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.153/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 --cfg 'feature=\"default\"' --cfg 'feature=\"std\"' -C metadata=da99be16f57977dd -C extra-filename=-da99be16f57977dd --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls --cfg freebsd11 --cfg libc_priv_mod_use --cfg libc_union --cfg libc_const_size_of --cfg libc_align --cfg libc_int128 --cfg libc_core_cvoid --cfg libc_packedN --cfg libc_cfg_target_vendor --cfg libc_non_exhaustive --cfg libc_long_array --cfg libc_ptr_addr_of --cfg libc_underscore_const_names --cfg libc_const_extern_fn`\n     Running `rustc --crate-name rustversion --edition=2018 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustversion-1.0.14/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type proc-macro --emit=dep-info,link -C prefer-dynamic -C embed-bitcode=no -C metadata=f520232a14502ece -C extra-filename=-f520232a14502ece --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --extern proc_macro --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n   Compiling cc v1.0.83\n     Running `rustc --crate-name cc --edition=2018 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cc-1.0.83/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C metadata=0f08763a90a2a5af -C extra-filename=-0f08763a90a2a5af --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --extern libc=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/liblibc-9cfae217150302a9.rmeta --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n    Checking getrandom v0.2.11\n     Running `rustc --crate-name getrandom --edition=2018 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/getrandom-0.2.11/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C metadata=c7d4a167956a7d2f -C extra-filename=-c7d4a167956a7d2f --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --extern cfg_if=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libcfg_if-419f92d015e31f97.rmeta --extern libc=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/liblibc-da99be16f57977dd.rmeta --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n   Compiling rustls v0.22.0\n     Running `rustc --crate-name build_script_build --edition=2021 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-0.22.0/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no --cfg 'feature=\"default\"' --cfg 'feature=\"log\"' --cfg 'feature=\"logging\"' --cfg 'feature=\"read_buf\"' --cfg 'feature=\"ring\"' --cfg 'feature=\"rustversion\"' --cfg 'feature=\"tls12\"' -C metadata=fe079e4e55a147b5 -C extra-filename=-fe079e4e55a147b5 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/build/rustls-fe079e4e55a147b5 -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --extern rustversion=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/librustversion-f520232a14502ece.so --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n   Compiling ring v0.17.5\n     Running `rustc --crate-name build_script_build --edition=2021 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ring-0.17.5/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no --cfg 'feature=\"alloc\"' --cfg 'feature=\"default\"' --cfg 'feature=\"dev_urandom_fallback\"' -C metadata=2ad0027317fdd8aa -C extra-filename=-2ad0027317fdd8aa --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/build/ring-2ad0027317fdd8aa -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --extern cc=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libcc-0f08763a90a2a5af.rlib --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls`\n     Running `/build/librustls/src/rustls-ffi-0.12.1/target/debug/build/ring-2ad0027317fdd8aa/build-script-build`\n     Running `rustc --crate-name ring --edition=2021 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ring-0.17.5/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 --cfg 'feature=\"alloc\"' --cfg 'feature=\"default\"' --cfg 'feature=\"dev_urandom_fallback\"' -C metadata=251b84f0addb0462 -C extra-filename=-251b84f0addb0462 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --extern getrandom=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libgetrandom-c7d4a167956a7d2f.rmeta --extern libc=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/liblibc-da99be16f57977dd.rmeta --extern spin=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libspin-a35495af919d6a27.rmeta --extern untrusted=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libuntrusted-a33f9bdba118a386.rmeta --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls -L native=/build/librustls/src/rustls-ffi-0.12.1/target/debug/build/ring-7e3f81a321f614ca/out -l static=ring_core_0_17_5_ -l static=ring_core_0_17_5_test`\n     Running `/build/librustls/src/rustls-ffi-0.12.1/target/debug/build/rustls-fe079e4e55a147b5/build-script-build`\n    Checking rustls-webpki v0.102.0\n     Running `rustc --crate-name webpki --edition=2021 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-webpki-0.102.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 --cfg 'feature=\"alloc\"' --cfg 'feature=\"default\"' --cfg 'feature=\"ring\"' --cfg 'feature=\"std\"' -C metadata=31952552a2440363 -C extra-filename=-31952552a2440363 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --extern ring=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libring-251b84f0addb0462.rmeta --extern pki_types=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/librustls_pki_types-c0b870f5fdf4ce28.rmeta --extern untrusted=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libuntrusted-a33f9bdba118a386.rmeta --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls -L native=/build/librustls/src/rustls-ffi-0.12.1/target/debug/build/ring-7e3f81a321f614ca/out`\n     Running `rustc --crate-name rustls --edition=2021 /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-0.22.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 --cfg 'feature=\"default\"' --cfg 'feature=\"log\"' --cfg 'feature=\"logging\"' --cfg 'feature=\"read_buf\"' --cfg 'feature=\"ring\"' --cfg 'feature=\"rustversion\"' --cfg 'feature=\"tls12\"' -C metadata=b182da02bb90d499 -C extra-filename=-b182da02bb90d499 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --extern log=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/liblog-bc3412dfc1f9b890.rmeta --extern ring=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libring-251b84f0addb0462.rmeta --extern pki_types=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/librustls_pki_types-c0b870f5fdf4ce28.rmeta --extern webpki=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libwebpki-31952552a2440363.rmeta --extern subtle=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libsubtle-f4be4d9978db3e65.rmeta --extern zeroize=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libzeroize-aa51ad6cd7f42774.rmeta --cap-lints allow -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls -L native=/build/librustls/src/rustls-ffi-0.12.1/target/debug/build/ring-7e3f81a321f614ca/out`\n     Running `rustc --crate-name rustls_ffi --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --crate-type staticlib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -Zunpretty=expanded --cfg 'feature=\"read_buf\"' -C metadata=a199015436cef2d1 -C extra-filename=-a199015436cef2d1 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -C incremental=/build/librustls/src/rustls-ffi-0.12.1/target/debug/incremental -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --extern libc=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/liblibc-da99be16f57977dd.rmeta --extern log=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/liblog-bc3412dfc1f9b890.rmeta --extern rustls=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/librustls-b182da02bb90d499.rmeta --extern rustls_pemfile=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/librustls_pemfile-1fa066e65a3c7932.rmeta --extern pki_types=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/librustls_pki_types-c0b870f5fdf4ce28.rmeta --extern webpki=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libwebpki-31952552a2440363.rmeta -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls -L native=/build/librustls/src/rustls-ffi-0.12.1/target/debug/build/ring-7e3f81a321f614ca/out`\nerror: the option `Z` is only accepted on the nightly compiler\n\nhelp: consider switching to a nightly toolchain: `rustup default nightly`\n\nnote: selecting a toolchain with `+toolchain` arguments require a rustup proxy; see <https://rust-lang.github.io/rustup/concepts/index.html>\n\nnote: for more information about Rust's stability policy, see <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html#unstable-features>\n\nerror: 1 nightly option were parsed\n\nerror: could not compile `rustls-ffi` (lib)\n\nCaused by:\n  process didn't exit successfully: `rustc --crate-name rustls_ffi --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --crate-type staticlib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -Zunpretty=expanded --cfg 'feature=\"read_buf\"' -C metadata=a199015436cef2d1 -C extra-filename=-a199015436cef2d1 --out-dir /build/librustls/src/rustls-ffi-0.12.1/target/debug/deps -C incremental=/build/librustls/src/rustls-ffi-0.12.1/target/debug/incremental -L dependency=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps --extern libc=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/liblibc-da99be16f57977dd.rmeta --extern log=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/liblog-bc3412dfc1f9b890.rmeta --extern rustls=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/librustls-b182da02bb90d499.rmeta --extern rustls_pemfile=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/librustls_pemfile-1fa066e65a3c7932.rmeta --extern pki_types=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/librustls_pki_types-c0b870f5fdf4ce28.rmeta --extern webpki=/build/librustls/src/rustls-ffi-0.12.1/target/debug/deps/libwebpki-31952552a2440363.rmeta -C debuginfo=2 --remap-path-prefix=/build/librustls/src=/usr/src/debug/librustls -L native=/build/librustls/src/rustls-ffi-0.12.1/target/debug/build/ring-7e3f81a321f614ca/out` (exit status: 1)\n"))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
==> ERROR: A failure occurred in build().
    Aborting...

@cpu
Copy link
Member

cpu commented Mar 27, 2024

@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 cbindgen feature that requires nightly for generating the rustls.h header.

@Kangie
Copy link

Kangie commented Mar 27, 2024

@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 cbindgen feature that requires nightly for generating the rustls.h header.

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:
mozilla/cbindgen#919

@cpu
Copy link
Member

cpu commented Mar 27, 2024

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!

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.

Building pkg-config files
Building header file using cbindgen
thread 'main' panicked at src/build.rs:55:10:

We vendor the cbindgen generated rustls.h in-repo, which would avoid needing cbindgen or nightly rustc, but I think the cargo-c build process is regenerating it as part of its build. Possibly one fix is figuring out if that's necessary at all.

@kpcyrd
Copy link
Contributor Author

kpcyrd commented Mar 27, 2024

Arch Linux also doesn't use a nightly compiler, instead the system-wide compiler at /usr/bin/rustc is used with RUSTC_BOOTSTRAP=1 to enable unstable features. This of course opts-out of the API stability guarantees of Rust (so things might break, which I'm fine dealing with). This approach might work for Gentoo too as a temporary solution (removing the need for this would be awesome of course!).

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants