From 238baeacfd0fa7e09ddd24e2a2a8fbad292468f0 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Tue, 9 Feb 2021 14:42:39 +0100 Subject: [PATCH] Add arm64 static build binary This adds an arm64 derivation to the static binary build. Signed-off-by: Sascha Grunert --- .cirrus.yml | 38 +++++++++++++++++ nix/default-arm64.nix | 95 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 nix/default-arm64.nix diff --git a/.cirrus.yml b/.cirrus.yml index 5beb1f2f..03dc659d 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -166,3 +166,41 @@ static_binary_task: save_cache_script: | mv /nix .cache chown -Rf $(whoami) .cache + +# Build the static binary for arm64 +static_binary_arm64_task: + depends_on: + - 'config' + - 'fmt' + + gce_instance: + image_name: "${FEDORA_CACHE_IMAGE_NAME}" + cpu: 8 + memory: 12 + disk: 200 + + init_script: | + set -ex + setenforce 0 + growpart /dev/sda 1 || true + resize2fs /dev/sda1 || true + yum -y install podman + + nix_arm64_cache: + folder: '.cache' + fingerprint_script: | + echo "nix-v1-$(sha1sum nix/nixpkgs.json | head -c 40)" + + build_script: | + set -ex + mkdir -p .cache + mv .cache /nix + if [[ -z $(ls -A /nix) ]]; then podman run --rm --privileged -ti -v /:/mnt nixos/nix cp -rfT /nix /mnt/nix; fi + podman run --rm --privileged -ti -v /nix:/nix -v ${PWD}:${PWD} -w ${PWD} nixos/nix nix --print-build-logs --option cores 8 --option max-jobs 8 build --file nix/default-arm64.nix + + binaries_artifacts: + path: "result/bin/conmon" + + save_cache_script: | + mv /nix .cache + chown -Rf $(whoami) .cache diff --git a/nix/default-arm64.nix b/nix/default-arm64.nix new file mode 100644 index 00000000..f6e08b6a --- /dev/null +++ b/nix/default-arm64.nix @@ -0,0 +1,95 @@ +let + pkgs = (import ./nixpkgs.nix { + crossSystem = { + config = "aarch64-unknown-linux-gnu"; + }; + overlays = [ + (final: pkg: { + pcre = (static pkg.pcre).overrideAttrs (x: { + configureFlags = x.configureFlags ++ [ + "--enable-static" + ]; + }); + }) + ]; + config = { + packageOverrides = pkg: { + autogen = (static pkg.autogen); + e2fsprogs = (static pkg.e2fsprogs); + libuv = (static pkg.libuv); + glib = (static pkg.glib).overrideAttrs (x: { + outputs = [ "bin" "out" "dev" ]; + mesonFlags = [ + "-Ddefault_library=static" + "-Ddevbindir=${placeholder ''dev''}/bin" + "-Dgtk_doc=false" + "-Dnls=disabled" + ]; + postInstall = '' + moveToOutput "share/glib-2.0" "$dev" + substituteInPlace "$dev/bin/gdbus-codegen" --replace "$out" "$dev" + sed -i "$dev/bin/glib-gettextize" -e "s|^gettext_dir=.*|gettext_dir=$dev/share/glib-2.0/gettext|" + sed '1i#line 1 "${x.pname}-${x.version}/include/glib-2.0/gobject/gobjectnotifyqueue.c"' \ + -i "$dev"/include/glib-2.0/gobject/gobjectnotifyqueue.c + ''; + }); + gnutls = (static pkg.gnutls).overrideAttrs (x: { + configureFlags = (x.configureFlags or [ ]) ++ [ + "--disable-non-suiteb-curves" + "--disable-openssl-compatibility" + "--disable-rpath" + "--enable-local-libopts" + "--without-p11-kit" + ]; + }); + systemd = (static pkg.systemd).overrideAttrs (x: { + outputs = [ "out" "dev" ]; + mesonFlags = x.mesonFlags ++ [ + "-Dstatic-libsystemd=true" + ]; + }); + }; + }; + }); + + static = pkg: pkg.overrideAttrs (x: { + doCheck = false; + configureFlags = (x.configureFlags or [ ]) ++ [ + "--without-shared" + "--disable-shared" + ]; + dontDisableStatic = true; + enableSharedExecutables = false; + enableStatic = true; + }); + + self = with pkgs; stdenv.mkDerivation rec { + name = "conmon"; + src = ./..; + vendorSha256 = null; + doCheck = false; + enableParallelBuilding = true; + outputs = [ "out" ]; + nativeBuildInputs = with buildPackages; [ + bash + gitMinimal + pcre + pkg-config + which + ]; + buildInputs = [ glibc glibc.static glib ]; + prePatch = '' + export CFLAGS='-static -pthread' + export LDFLAGS='-s -w -static-libgcc -static' + export EXTRA_LDFLAGS='-s -w -linkmode external -extldflags "-static -lm"' + ''; + buildPhase = '' + patchShebangs . + make + ''; + installPhase = '' + install -Dm755 bin/conmon $out/bin/conmon + ''; + }; +in +self