Skip to content

Commit

Permalink
keyfender: upgrade to libgmp 6.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ansiwen committed May 4, 2024
1 parent f5af470 commit 56c16d7
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/container/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ EOF
ARG OPAM_REPOSITORY_COMMIT
COPY --chown=1000:1000 src/keyfender/keyfender.opam.locked /home/opam/
COPY --chown=1000:1000 src/s_keyfender/unikernel-preinstall.opam.locked /home/opam/
COPY --chown=1000:1000 src/container/builder/gmp-freestanding /home/opam/gmp-6.3.0/
RUN --mount=type=tmpfs,target=/tmp --mount=type=cache,target=/home/opam/.opam/download-cache,uid=1000,gid=1000 <<EOF
opam repository set-url default git+https://github.com/ocaml/opam-repository#${OPAM_REPOSITORY_COMMIT}
curl -sSL "https://gmplib.org/download/gmp/gmp-6.3.0.tar.xz" | tar Jxpf - -C /home/opam
patch -p1 -d /home/opam/gmp-6.3.0/ </home/opam/gmp-6.3.0/libgmp-fat.patch
opam pin -y -n gmp-freestanding.6.3.0 /home/opam/gmp-6.3.0/
opam update
OPAMJOBS=$(nproc) opam install -y dune
OPAMJOBS=$(nproc) opam install -y --deps-only --locked --ignore-pin-depends /home/opam/keyfender.opam.locked
Expand Down
12 changes: 12 additions & 0 deletions src/container/builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,25 @@ EOF
ARG OPAM_REPOSITORY_COMMIT
COPY --chown=1000:1000 keyfender.opam.locked /home/opam/
COPY --chown=1000:1000 unikernel-preinstall.opam.locked /home/opam/
COPY --chown=1000:1000 gmp-freestanding /home/opam/gmp-6.3.0/
RUN --mount=type=tmpfs,target=/tmp --mount=type=cache,target=/home/opam/.opam/download-cache,uid=1000,gid=1000 <<EOF
opam repository set-url default git+https://github.com/ocaml/opam-repository#${OPAM_REPOSITORY_COMMIT}
curl -sSL "https://gmplib.org/download/gmp/gmp-6.3.0.tar.xz" | tar Jxpf - -C /home/opam
patch -p1 -d /home/opam/gmp-6.3.0/ </home/opam/gmp-6.3.0/libgmp-fat.patch
opam pin -y -n gmp-freestanding.6.3.0 /home/opam/gmp-6.3.0/
opam update
OPAMJOBS=$(nproc) opam install -y dune containers ezjsonm yaml ocamlformat
OPAMJOBS=$(nproc) opam install -y --deps-only --with-test --locked --ignore-pin-depends /home/opam/keyfender.opam.locked
OPAMJOBS=$(nproc) opam install -y --deps-only --with-test --locked --ignore-pin-depends /home/opam/unikernel-preinstall.opam.locked
EOF

COPY --chown=1000:1000 gmp-freestanding /home/opam/gmp-6.3.0/
RUN --mount=type=tmpfs,target=/tmp --mount=type=cache,target=/home/opam/.opam/download-cache,uid=1000,gid=1000 <<EOF
curl -sSL "https://gmplib.org/download/gmp/gmp-6.3.0.tar.xz" | tar Jxpf - -C /home/opam
patch -p1 </home/opam/gmp-6.3.0/libgmp-fat.patch -d /home/opam/gmp-6.3.0/
opam pin -y gmp-freestanding /home/opam/gmp-6.3.0/
EOF

# Remove opam cache directory
RUN rmdir /home/opam/.opam/download-cache 2>/dev/null || true

Expand Down
22 changes: 22 additions & 0 deletions src/container/builder/gmp-freestanding/gmp-freestanding.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
opam-version: "2.0"
synopsis: "The GNU Multiple Precision Arithmetic Library"
description: "Freestanding build of GNU GMP."
maintainer: "Martin Lucina <martin@lucina.net>"
authors: "Torbjörn Granlund and contributors"
license: ["LGPL-3.0-only" "LGPL-2.0-only"]
homepage: "https://gmplib.org/"
bug-reports: "mirageos-devel@lists.xenproject.org"
depends: [
"ocaml"
"ocaml-freestanding" {>= "0.4.1" & < "0.7.0"}
"conf-m4" {build}
]
flags: light-uninstall
build: ["sh" "-ex" "./mirage-build.sh"]
install: ["sh" "-ex" "./mirage-install.sh"]
remove: [
"rm"
"-rf"
"%{prefix}%/lib/pkgconfig/gmp-freestanding.pc"
"%{prefix}%/lib/gmp-freestanding"
]
9 changes: 9 additions & 0 deletions src/container/builder/gmp-freestanding/gmp-freestanding.pc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
libdir=${pcfiledir}/../gmp-freestanding
includedir=${libdir}/include

Name: gmp-freestanding
Version: 6.3.0
URL: https://gmplib.org
Description: The GNU Multiple Precision Arithmetic Library
Cflags: -I${includedir}
Libs: -L${libdir} -lgmp-freestanding
18 changes: 18 additions & 0 deletions src/container/builder/gmp-freestanding/libgmp-fat.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- a/mpn/x86_64/fat/fat.c
+++ b/mpn/x86_64/fat/fat.c
@@ -375,6 +375,7 @@ __gmpn_cpuvec_init (void)
CPUVEC_SETUP_core2;
CPUVEC_SETUP_coreinhm;
CPUVEC_SETUP_coreisbr;
+ __gmpn_cpuid (dummy_string, 7);
if ((dummy_string[0 + BMI2_BIT / 8] & (1 << (BMI2_BIT % 8))) == 0)
break;
CPUVEC_SETUP_coreihwl;
@@ -388,6 +389,7 @@ __gmpn_cpuvec_init (void)
CPUVEC_SETUP_core2;
CPUVEC_SETUP_coreinhm;
CPUVEC_SETUP_coreisbr;
+ __gmpn_cpuid (dummy_string, 7);
if ((dummy_string[0 + BMI2_BIT / 8] & (1 << (BMI2_BIT % 8))) == 0)
break;
if (gmp_workaround_skylake_cpuid_bug ())
43 changes: 43 additions & 0 deletions src/container/builder/gmp-freestanding/mirage-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh -ex
if [ -z "$PREFIX" ]; then
PREFIX="`opam config var prefix`/lib/gmp-freestanding"
fi

PKG_CONFIG_DEPS="ocaml-freestanding"
check_deps () {
pkg-config --print-errors --exists ${PKG_CONFIG_DEPS}
}

if ! check_deps 2>/dev/null; then
# rely on `opam` if deps are unavailable
export PKG_CONFIG_PATH="`opam config var prefix`/lib/pkgconfig"
fi
check_deps || exit 1

#
# ocaml-freestanding does not provide a real cross compiler, so we fake it:
#
# - set CC to stop configure trying to find a host compiler
# - set CPPFLAGS to ocaml-freestanding CFLAGS, this prevents inclusion of
# system headers
# - manually override tests for missing functions
# - manually trim the components (SUBDIRS) of libgmp we build to the subset
# actually used by zarith-freestanding (our sole dependency)
# - set -Werror=implicit-function-declaration at *build* time to catch any
# undefined symbols
#
# Further, with the introduction of -fstack-protector-strong in Solo5, override
# this during './configure' to prevent it complaining that the compiler does not
# work, and reinstate it again during 'make'.
#
FREESTANDING_CFLAGS="$(pkg-config --cflags ${PKG_CONFIG_DEPS})"
ac_cv_func_obstack_vprintf=no \
ac_cv_func_localeconv=no \
./configure \
--host=$(uname -m)-unknown-none --enable-fat --disable-shared --with-pic=no \
CC=cc "CPPFLAGS=${FREESTANDING_CFLAGS} -fno-stack-protector"

make SUBDIRS="mpn mpz mpq mpf" \
PRINTF_OBJECTS= SCANF_OBJECTS= \
CPPFLAGS="${FREESTANDING_CFLAGS}" \
CFLAGS+=-Werror=implicit-function-declaration
14 changes: 14 additions & 0 deletions src/container/builder/gmp-freestanding/mirage-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh -ex
if [ -z "$PREFIX" ]; then
PREFIX=`opam config var prefix`
fi
PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig
LIBDIR=${PREFIX}/lib/gmp-freestanding

mkdir -p ${PKG_CONFIG_PATH}
cp gmp-freestanding.pc ${PKG_CONFIG_PATH}
mkdir -p ${LIBDIR}
cp .libs/libgmp.a ${LIBDIR}/libgmp-freestanding.a
touch ${LIBDIR}/META
mkdir -p ${LIBDIR}/include
cp gmp.h ${LIBDIR}/include
2 changes: 1 addition & 1 deletion src/s_keyfender/unikernel-preinstall.opam.locked
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ depends: [
"gluten" {= "0.5.0"}
"gluten-lwt" {= "0.5.0"}
"gmap" {= "0.3.0"}
"gmp-freestanding" {= "6.2.1"}
"gmp-freestanding" {= "6.3.0"}
"happy-eyeballs" {= "0.5.0"}
"hex" {= "1.5.0"}
"hkdf" {= "1.0.4"}
Expand Down

0 comments on commit 56c16d7

Please sign in to comment.