From 65b416a2d9691fcda1393d577e6d52ddf9144fe1 Mon Sep 17 00:00:00 2001 From: DingDongSoLong4 <99329275+DingDongSoLong4@users.noreply.github.com> Date: Mon, 20 Nov 2023 02:26:57 +0200 Subject: [PATCH] Fix FreeBSD cross-compilation (#4251) * Cleanup compiler container * Fix FreeBSD cross-compilation * Bump compiler version --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com> --- .github/workflows/build.yml | 2 +- Makefile | 5 +- docker/compiler/Dockerfile | 108 +++++++++++++++++++++--------------- docker/compiler/Makefile | 2 +- 4 files changed, 66 insertions(+), 51 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e4157e1b4..b61d4799a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ concurrency: cancel-in-progress: true env: - COMPILER_IMAGE: stashapp/compiler:7 + COMPILER_IMAGE: stashapp/compiler:8 jobs: build: diff --git a/Makefile b/Makefile index c9fe2ffb0..18b886265 100644 --- a/Makefile +++ b/Makefile @@ -145,7 +145,6 @@ stash-macapp: flags-release flags-pie stash build-cc-windows: export GOOS := windows build-cc-windows: export GOARCH := amd64 build-cc-windows: export CC := x86_64-w64-mingw32-gcc -build-cc-windows: export CXX := x86_64-w64-mingw32-g++ build-cc-windows: STASH_OUTPUT := -o dist/stash-win.exe build-cc-windows: PHASHER_OUTPUT :=-o dist/phasher-win.exe build-cc-windows: flags-release @@ -156,7 +155,6 @@ build-cc-windows: build build-cc-macos-intel: export GOOS := darwin build-cc-macos-intel: export GOARCH := amd64 build-cc-macos-intel: export CC := o64-clang -build-cc-macos-intel: export CXX := o64-clang++ build-cc-macos-intel: STASH_OUTPUT := -o dist/stash-macos-intel build-cc-macos-intel: PHASHER_OUTPUT := -o dist/phasher-macos-intel build-cc-macos-intel: flags-release @@ -168,7 +166,6 @@ build-cc-macos-intel: build build-cc-macos-arm: export GOOS := darwin build-cc-macos-arm: export GOARCH := arm64 build-cc-macos-arm: export CC := oa64e-clang -build-cc-macos-arm: export CXX := oa64e-clang++ build-cc-macos-arm: STASH_OUTPUT := -o dist/stash-macos-arm build-cc-macos-arm: PHASHER_OUTPUT := -o dist/phasher-macos-arm build-cc-macos-arm: flags-release @@ -198,6 +195,7 @@ build-cc-macos: .PHONY: build-cc-freebsd build-cc-freebsd: export GOOS := freebsd build-cc-freebsd: export GOARCH := amd64 +build-cc-freebsd: export CC := clang -target x86_64-unknown-freebsd12.0 --sysroot=/opt/cross-freebsd build-cc-freebsd: STASH_OUTPUT := -o dist/stash-freebsd build-cc-freebsd: PHASHER_OUTPUT := -o dist/phasher-freebsd build-cc-freebsd: flags-release @@ -253,6 +251,7 @@ build-cc-all: make build-cc-linux-arm64v8 make build-cc-linux-arm32v7 make build-cc-linux-arm32v6 + make build-cc-freebsd .PHONY: touch-ui touch-ui: diff --git a/docker/compiler/Dockerfile b/docker/compiler/Dockerfile index be015831d..d543ca20c 100644 --- a/docker/compiler/Dockerfile +++ b/docker/compiler/Dockerfile @@ -2,66 +2,82 @@ FROM golang:1.19 LABEL maintainer="https://discord.gg/2TsNFKt" -# Install tools -RUN apt-get update && apt-get install -y apt-transport-https -RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash - +RUN apt-get update && apt-get install -y apt-transport-https ca-certificates gnupg + +RUN mkdir -p /etc/apt/keyrings + +ADD https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key nodesource.gpg.key +RUN cat nodesource.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && rm nodesource.gpg.key +RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list -# prevent caching of the key ADD https://dl.yarnpkg.com/debian/pubkey.gpg yarn.gpg -RUN cat yarn.gpg | apt-key add - && \ - echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ - rm yarn.gpg +RUN cat yarn.gpg | gpg --dearmor -o /etc/apt/keyrings/yarn.gpg && rm yarn.gpg +RUN echo "deb [signed-by=/etc/apt/keyrings/yarn.gpg] https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list RUN apt-get update && \ - apt-get install -y automake autogen cmake \ - libtool libxml2-dev uuid-dev libssl-dev bash \ - patch make tar xz-utils bzip2 gzip zlib1g-dev sed cpio \ - gcc-10-multilib gcc-mingw-w64 g++-mingw-w64 clang llvm-dev \ - gcc-arm-linux-gnueabi libc-dev-armel-cross linux-libc-dev-armel-cross \ - gcc-arm-linux-gnueabihf libc-dev-armhf-cross \ - gcc-aarch64-linux-gnu libc-dev-arm64-cross \ - nodejs yarn zip --no-install-recommends || exit 1; \ - rm -rf /var/lib/apt/lists/*; + apt-get install -y --no-install-recommends \ + git make tar bash nodejs yarn zip \ + clang llvm-dev cmake patch libxml2-dev uuid-dev libssl-dev xz-utils \ + bzip2 gzip sed cpio libbz2-dev zlib1g-dev \ + gcc-mingw-w64 \ + gcc-arm-linux-gnueabi libc-dev-armel-cross linux-libc-dev-armel-cross \ + gcc-aarch64-linux-gnu libc-dev-arm64-cross && \ + rm -rf /var/lib/apt/lists/*; -# Cross compile setup -ENV OSX_SDK_VERSION 11.3 -ENV OSX_SDK_DOWNLOAD_FILE=MacOSX${OSX_SDK_VERSION}.sdk.tar.xz -ENV OSX_SDK_DOWNLOAD_URL=https://github.com/phracker/MacOSX-SDKs/releases/download/${OSX_SDK_VERSION}/${OSX_SDK_DOWNLOAD_FILE} -ENV OSX_SDK_SHA=cd4f08a75577145b8f05245a2975f7c81401d75e9535dcffbb879ee1deefcbf4 -ENV OSX_SDK MacOSX$OSX_SDK_VERSION.sdk -ENV OSX_NDK_X86 /usr/local/osx-ndk-x86 +# FreeBSD cross-compilation setup +# https://github.com/smartmontools/docker-build/blob/6b8c92560d17d325310ba02d9f5a4b250cb0764a/Dockerfile#L66 +ENV FREEBSD_VERSION 12.4 +ENV FREEBSD_DOWNLOAD_URL http://ftp.plusline.de/FreeBSD/releases/amd64/${FREEBSD_VERSION}-RELEASE/base.txz +ENV FREEBSD_SHA 581c7edacfd2fca2bdf5791f667402d22fccd8a5e184635e0cac075564d57aa8 -RUN wget ${OSX_SDK_DOWNLOAD_URL} -RUN echo "$OSX_SDK_SHA $OSX_SDK_DOWNLOAD_FILE" | sha256sum -c - || exit 1; \ - git clone https://github.com/tpoechtrager/osxcross.git; \ - mv $OSX_SDK_DOWNLOAD_FILE osxcross/tarballs/ +RUN cd /tmp && \ + curl -o base.txz $FREEBSD_DOWNLOAD_URL && \ + echo "$FREEBSD_SHA base.txz" | sha256sum -c - && \ + mkdir -p /opt/cross-freebsd && \ + cd /opt/cross-freebsd && \ + tar -xf /tmp/base.txz ./lib/ ./usr/lib/ ./usr/include/ && \ + rm -f /tmp/base.txz && \ + cd /opt/cross-freebsd/usr/lib && \ + find . -xtype l | xargs ls -l | grep ' /lib/' | awk '{print "ln -sf /opt/cross-freebsd"$11 " " $9}' | /bin/sh && \ + ln -s libc++.a libstdc++.a && \ + ln -s libc++.so libstdc++.so -RUN UNATTENDED=yes SDK_VERSION=${OSX_SDK_VERSION} OSX_VERSION_MIN=10.10 osxcross/build.sh || exit 1; -RUN cp osxcross/target/lib/* /usr/lib/ ; \ - mv osxcross/target $OSX_NDK_X86; \ - rm -rf osxcross; +# macOS cross-compilation setup +ENV OSX_SDK_VERSION 11.3 +ENV OSX_SDK_DOWNLOAD_FILE MacOSX${OSX_SDK_VERSION}.sdk.tar.xz +ENV OSX_SDK_DOWNLOAD_URL https://github.com/phracker/MacOSX-SDKs/releases/download/${OSX_SDK_VERSION}/${OSX_SDK_DOWNLOAD_FILE} +ENV OSX_SDK_SHA cd4f08a75577145b8f05245a2975f7c81401d75e9535dcffbb879ee1deefcbf4 +ENV OSXCROSS_REVISION 5e1b71fcceb23952f3229995edca1b6231525b5b +ENV OSXCROSS_DOWNLOAD_URL https://codeload.github.com/tpoechtrager/osxcross/tar.gz/${OSXCROSS_REVISION} +ENV OSXCROSS_SHA d3f771bbc20612fea577b18a71be3af2eb5ad2dd44624196cf55de866d008647 -ENV PATH $OSX_NDK_X86/bin:$PATH +RUN cd /tmp && \ + curl -o osxcross.tar.gz $OSXCROSS_DOWNLOAD_URL && \ + echo "$OSXCROSS_SHA osxcross.tar.gz" | sha256sum -c - && \ + mkdir osxcross && \ + tar --strip=1 -C osxcross -xf osxcross.tar.gz && \ + rm -f osxcross.tar.gz && \ + curl -Lo $OSX_SDK_DOWNLOAD_FILE $OSX_SDK_DOWNLOAD_URL && \ + echo "$OSX_SDK_SHA $OSX_SDK_DOWNLOAD_FILE" | sha256sum -c - && \ + mv $OSX_SDK_DOWNLOAD_FILE osxcross/tarballs/ && \ + UNATTENDED=yes SDK_VERSION=$OSX_SDK_VERSION OSX_VERSION_MIN=10.10 osxcross/build.sh && \ + cp osxcross/target/lib/* /usr/lib/ && \ + mv osxcross/target /opt/osx-ndk-x86 && \ + rm -rf /tmp/osxcross -RUN mkdir -p /root/.ssh; \ - chmod 0700 /root/.ssh; \ - ssh-keyscan github.com > /root/.ssh/known_hosts; +ENV PATH /opt/osx-ndk-x86/bin:$PATH -# Notes for self: +RUN mkdir -p /root/.ssh && \ + chmod 0700 /root/.ssh && \ + ssh-keyscan github.com > /root/.ssh/known_hosts + +# ignore "dubious ownership" errors +RUN git config --global safe.directory '*' # To test locally: # make generate # make ui # cd docker/compiler # make build -# docker run -it -v /PATH_TO_STASH:/go/stash stashapp/compiler:latest /bin/bash -# cd stash -# make cross-compile-all +# docker run --rm -v /PATH_TO_STASH:/stash -w /stash -i -t stashapp/compiler:latest make build-cc-all # # binaries will show up in /dist - -# Windows: -# GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -ldflags "-extldflags '-static'" -tags extended - -# Darwin -# CC=o64-clang CXX=o64-clang++ GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -tags extended -# env goreleaser --config=goreleaser-extended.yml --skip-publish --skip-validate --rm-dist --release-notes=temp/0.48-relnotes-ready.md diff --git a/docker/compiler/Makefile b/docker/compiler/Makefile index e4117a968..2dd2f1e08 100644 --- a/docker/compiler/Makefile +++ b/docker/compiler/Makefile @@ -1,6 +1,6 @@ user=stashapp repo=compiler -version=7 +version=8 latest: docker build -t ${user}/${repo}:latest .