Skip to content

Commit

Permalink
Freebsd support (#191)
Browse files Browse the repository at this point in the history
* Add freebsd support

* correct path
  • Loading branch information
techknowlogick authored Jan 10, 2023
1 parent 7974851 commit 1fd3d5b
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ RUN \

ENV PATH /osxcross/target/bin:$PATH

###########################
# FREEBSD TOOLCHAIN BUILD #
###########################

ADD prep_freebsd.sh /prep_freebsd.sh
RUN chmod +x /prep_freebsd.sh && \
/prep_freebsd.sh

ENV PATH /freebsdcross/x86_64-pc-freebsd12/bin:$PATH

# Inject the new Go root distribution downloader and bootstrapper
ADD bootstrap_pure.sh /bootstrap_pure.sh
ENV BOOTSTRAP_PURE /bootstrap_pure.sh
Expand Down
3 changes: 3 additions & 0 deletions docker/base/bootstrap_pure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go install std
echo "Bootstrapping windows/386..."
GOOS=windows GOARCH=386 CGO_ENABLED=1 CC=i686-w64-mingw32-gcc go install std

echo "Bootstrapping freebsd/amd64..."
GOOS=freebsd GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-pc-freebsd12-gcc go install std

echo "Bootstrapping darwin/amd64..."
GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 CC=o64-clang go install std

Expand Down
18 changes: 18 additions & 0 deletions docker/base/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,24 @@ for TARGET in $TARGETS; do
# Remove any automatically injected deployment target vars
unset MACOSX_DEPLOYMENT_TARGET
fi
# Check and build for freebsd targets
if [ "$XGOOS" == "." ] || [[ "$XGOOS" == freebsd* ]]; then
# Build the requested freebsd binaries
if [ "$XGOARCH" == "." ] || [ "$XGOARCH" == "amd64" ]; then
echo "Compiling for freebsd/amd64..."
CC=x86_64-pc-freebsd12-gcc HOST=x86_64-pc-freebsd12 PREFIX=/freebsdcross/x86_64-pc-freebsd12 $BUILD_DEPS /deps "${DEPS_ARGS[@]}"
export PKG_CONFIG_PATH=/freebsdcross/x86_64-pc-freebsd12/lib/pkgconfig

if [[ "$USEMODULES" == false ]]; then
CC=x86_64-pc-freebsd12-gcc CXX=x86_64-pc-freebsd12-g++ GOOS=freebsd GOARCH=amd64 CGO_ENABLED=1 go get $V $X "${T[@]}" -d "$PACK_RELPATH"
fi
CC=x86_64-pc-freebsd12-gcc CXX=x86_64-pc-freebsd12-g++ GOOS=freebsd GOARCH=amd64 CGO_ENABLED=1 go build $V $X $TP "${MOD[@]}" "${T[@]}" "${LDF[@]}" "${GC[@]}" "${BM[@]}" -o "/build/$NAME-freebsd12-amd64$(extension freebsd)" "$PACK_RELPATH"
fi
if [ "$XGOARCH" == "." ] || [ "$XGOARCH" == "arm64" ]; then
echo "skipping freebsd/arm64... as it is not yet supported"
# TODO: add arm64 support
fi
fi
done

# Clean up any leftovers for subsequent build invocations
Expand Down
87 changes: 87 additions & 0 deletions docker/base/prep_freebsd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

# big thanks to:
# @mcandre
# @samm-git
# @mcilloni
# @marcelog
# @bijanebrahimi
# for their work on this subject which
# I have been able to expand upon for cgo/golang

freebsd_ver=12
freebsd_full_ver=12.4
binutils_ver=2.39
gmp_ver=6.2.1
mpfr_ver=4.1.1
mpc_ver=1.3.1
gcc_ver=7.5.0

mkdir -p /freebsdcross/x86_64-pc-freebsd${freebsd_ver}

# binutils
mkdir /tmp/freebsdbuild && cd /tmp/freebsdbuild && \
wget https://ftp.gnu.org/gnu/binutils/binutils-${binutils_ver}.tar.xz && \
tar -xf binutils-${binutils_ver}.tar.xz && cd binutils-${binutils_ver} && \
./configure --enable-libssp --enable-gold --enable-ld \
--target=x86_64-pc-freebsd${freebsd_ver} --prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} && make -j4 && \
make install && \
rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild

# freebsd specific lbs
cd /tmp/freebsdbuild && \
wget https://download.freebsd.org/ftp/releases/amd64/${freebsd_full_ver}-RELEASE/base.txz && \
cd /freebsdcross/x86_64-pc-freebsd${freebsd_ver} && \
tar -xf /tmp/freebsdbuild/base.txz ./lib/ ./usr/lib/ ./usr/include/ && \
cd /freebsdcross/x86_64-pc-freebsd${freebsd_ver}/usr/lib && \
find . -xtype l|xargs ls -l|grep ' /lib/' \
| awk '{print "ln -sf /freebsdcross/x86_64-pc-freebsd12"$11 " " $9}' \
| /bin/sh && \
rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild

# Compile GMP
cd /tmp/freebsdbuild && \
wget https://ftp.gnu.org/gnu/gmp/gmp-${gmp_ver}.tar.xz && \
tar -xf gmp-${gmp_ver}.tar.xz && \
cd gmp-${gmp_ver} && \
./configure --prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --enable-shared --enable-static \
--enable-fft --enable-cxx --host=x86_64-pc-freebsd${freebsd_ver} && \
make -j4 && make install && \
rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild

# Compile MPFR
cd /tmp/freebsdbuild && \
wget https://ftp.gnu.org/gnu/mpfr/mpfr-${mpfr_ver}.tar.xz && tar -xf mpfr-${mpfr_ver}.tar.xz && \
cd mpfr-${mpfr_ver} && \
./configure --prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --with-gnu-ld --enable-static \
--enable-shared --with-gmp=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --host=x86_64-pc-freebsd${freebsd_ver} && \
make -j4 && make install && \
rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild

# Compile MPC
cd /tmp/freebsdbuild && \
wget https://ftp.gnu.org/gnu/mpc/mpc-${mpc_ver}.tar.gz && tar -xf mpc-${mpc_ver}.tar.gz && \
cd mpc-${mpc_ver} && \
./configure --prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --with-gnu-ld --enable-static \
--enable-shared --with-gmp=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} \
--with-mpfr=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --host=x86_64-pc-freebsd${freebsd_ver} && \
make -j4 && make install && \
rm -rf /tmp/freebsdbuild && mkdir /tmp/freebsdbuild

# gcc (change LD_LIBRARY_PATH to /freebsdcross or something)
cd /tmp/freebsdbuild && \
wget https://ftp.gnu.org/gnu/gcc/gcc-${gcc_ver}/gcc-${gcc_ver}.tar.xz && \
tar xf gcc-${gcc_ver}.tar.xz && \
cd gcc-${gcc_ver} && mkdir build && cd build && \
../configure --without-headers --with-gnu-as --with-gnu-ld --disable-nls \
--enable-languages=c,c++ --enable-libssp --enable-gold --enable-ld \
--disable-libitm --disable-libquadmath --target=x86_64-pc-freebsd${freebsd_ver} \
--prefix=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --with-gmp=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} \
--with-mpc=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --with-mpfr=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} --disable-libgomp \
--with-sysroot=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} \
--with-build-sysroot=/freebsdcross/x86_64-pc-freebsd${freebsd_ver} && \
cd /tmp/freebsdbuild/gcc-${gcc_ver} && \
echo '#define HAVE_ALIGNED_ALLOC 1' >> libstdc++-v3/config.h.in && \
cd /tmp/freebsdbuild/gcc-${gcc_ver}/build && \
make -j4 && make install && \
rm -rf /tmp/freebsdbuild

0 comments on commit 1fd3d5b

Please sign in to comment.