-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tools/sgx,curl] Minimize and build libcurl statically
Previously, we built `libsgx_util` as a shared library which was linked into RA-TLS, Secret Provisioning libraries and some other tools. This library relied on libcurl taken from the host platform. However, libcurl has a high number of dependencies itself, most of which are not required by Gramine, only consume space and are hard to track and reason about. This is especially pronounced for the RA-TLS/SecretProv libs because they typically run inside SGX enclaves and therefore should be minimal and reproducible. This patch: - builds `libsgx_util` into a static library, - builds and minimizes `libcurl` into a static library (leveraging `mbedtls` as the TLS backend), - links all dependencies of `tools/sgx` statically to avoid pulling in a lot of dependencies. Co-authored-by: Wojtek Porczyk <[email protected]> Signed-off-by: Kailun Qin <[email protected]> Signed-off-by: Wojtek Porczyk <[email protected]>
- Loading branch information
1 parent
cda5d4d
commit c15ca88
Showing
16 changed files
with
200 additions
and
26 deletions.
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/packagecache | ||
|
||
/cJSON-*/ | ||
/curl-*/ | ||
/gcc-*/ | ||
/glibc-*/ | ||
/mbedtls-*/ | ||
|
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[wrap-file] | ||
directory = curl-7.84.0 | ||
source_url = https://github.com/curl/curl/releases/download/curl-7_84_0/curl-7.84.0.tar.gz | ||
source_fallback_url = https://packages.gramineproject.io/distfiles/curl-7.84.0.tar.gz | ||
source_filename = curl-7.84.0.tar.gz | ||
source_hash = 3c6893d38d054d4e378267166858698899e9d87258e8ff1419d020c395384535 | ||
patch_directory = curl-7.84.0 |
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
log() { | ||
echo "curl: $*" | ||
} | ||
|
||
CURRENT_SOURCE_DIR="$1" | ||
CURRENT_BUILD_DIR="$2" | ||
PRIVATE_DIR="$3" | ||
SUBPROJ_ROOT="$4" | ||
shift 4 | ||
|
||
BUILD_LOG=$(realpath "$CURRENT_BUILD_DIR/curl-build.log") | ||
rm -f "$BUILD_LOG" | ||
|
||
log "see $BUILD_LOG for full build log" | ||
|
||
log "preparing sources..." | ||
|
||
rm -rf "$PRIVATE_DIR" | ||
cp -ar "$CURRENT_SOURCE_DIR" "$PRIVATE_DIR" | ||
|
||
( | ||
cd "$PRIVATE_DIR" | ||
|
||
log "running configure..." | ||
# The list of configure options is selected based on: | ||
# https://github.com/curl/curl/blob/curl-7_84_0/docs/INSTALL.md#reducing-size | ||
./configure \ | ||
--disable-alt-svc \ | ||
--disable-ares \ | ||
--disable-cookies \ | ||
--disable-crypto-auth \ | ||
--disable-dateparse \ | ||
--disable-dict \ | ||
--disable-dnsshuffle \ | ||
--disable-doh \ | ||
--disable-file \ | ||
--disable-ftp \ | ||
--disable-get-easy-options \ | ||
--disable-gopher \ | ||
--disable-hsts \ | ||
--disable-http-auth \ | ||
--disable-imap \ | ||
--disable-ldap \ | ||
--disable-ldaps \ | ||
--disable-libcurl-option \ | ||
--disable-manual \ | ||
--disable-mqtt \ | ||
--disable-netrc \ | ||
--disable-ntlm-wb \ | ||
--disable-pop3 \ | ||
--disable-progress-meter \ | ||
--disable-proxy \ | ||
--disable-pthreads \ | ||
--disable-rtsp \ | ||
--disable-shared \ | ||
--disable-smb \ | ||
--disable-smtp \ | ||
--disable-socketpair \ | ||
--disable-telnet \ | ||
--disable-tftp \ | ||
--disable-threaded-resolver \ | ||
--disable-tls-srp \ | ||
--disable-unix-sockets \ | ||
--disable-verbose \ | ||
--disable-versioned-symbols \ | ||
--with-mbedtls="$SUBPROJ_ROOT"/mbedtls-curl \ | ||
--without-brotli \ | ||
--without-libidn2 \ | ||
--without-libpsl \ | ||
--without-librtmp \ | ||
--without-nghttp2 \ | ||
--without-ngtcp2 \ | ||
--without-zlib \ | ||
--without-zstd \ | ||
>>"$BUILD_LOG" 2>&1 | ||
|
||
log "running make..." | ||
|
||
# The curl executable is not needed so we only build libcurl here. | ||
cd lib; make -j"$(nproc)" >>"$BUILD_LOG" 2>&1 | ||
) | ||
|
||
cp -r "$PRIVATE_DIR"/lib/.libs/* "$CURRENT_BUILD_DIR"/ | ||
|
||
log "done" |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
void dummy() {} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
project('curl', 'c', version: '7.84.0') | ||
|
||
mbedtls_gramine = dependency('mbedtls_curl') | ||
|
||
# This dummy target is needed, because custom_target(depends:) needs a "target", not a "dependency" | ||
mbedtls_dummy_target = static_library('dummy', 'dummy.c', dependencies: mbedtls_gramine) | ||
|
||
curl_libs_output = [ | ||
'libcurl.a', | ||
] | ||
|
||
curl = custom_target('curl', | ||
command: [ | ||
find_program('compile.sh'), | ||
'@CURRENT_SOURCE_DIR@', | ||
meson.current_build_dir(), | ||
'@PRIVATE_DIR@', | ||
join_paths(meson.build_root(), 'subprojects'), | ||
], | ||
|
||
depends: mbedtls_dummy_target, | ||
output: curl_libs_output, | ||
) | ||
|
||
curl_minimal_dep = declare_dependency( | ||
link_with: curl, | ||
include_directories: 'include', | ||
) |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/sh | ||
|
||
set -ex | ||
|
||
CURRENT_SOURCE_DIR="$1" | ||
VENDOR_SOURCE_DIR="$2" | ||
CURRENT_BUILD_DIR="$3" | ||
PRIVATE_DIR="$4" | ||
SUBPROJ_ROOT="$5" | ||
shift 5 | ||
|
||
rm -rf "$PRIVATE_DIR" | ||
|
||
cp -ar "$VENDOR_SOURCE_DIR" "$PRIVATE_DIR" | ||
cp "$CURRENT_SOURCE_DIR"/include/mbedtls/*.h "$PRIVATE_DIR"/include/mbedtls/ | ||
patch -p1 --directory "$PRIVATE_DIR" <"$CURRENT_SOURCE_DIR"/gramine.patch | ||
patch -p1 --directory "$PRIVATE_DIR" <"$CURRENT_SOURCE_DIR"/fcntl.patch | ||
|
||
make -C "$PRIVATE_DIR" lib SUFFIX="''" install DESTDIR="$SUBPROJ_ROOT"/mbedtls-curl | ||
touch "$PRIVATE_DIR"/library/mbedtls-curl-dummy.h | ||
|
||
for output in $@ | ||
do | ||
cp -a "$PRIVATE_DIR"/library/"$(basename "$output")" "$output" | ||
done |
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,7 +1,6 @@ | ||
#!/bin/sh | ||
|
||
set -x | ||
set -e | ||
set -ex | ||
|
||
CURRENT_SOURCE_DIR="$1" | ||
VENDOR_SOURCE_DIR="$2" | ||
|
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