GithubHelp home page GithubHelp logo

mrdos / freebsd-cross-build Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 2.0 37 KB

amd64 Linux docker container for cross-compilation to FreeBSD.

License: MIT License

Dockerfile 15.13% Makefile 18.65% Shell 66.22%

freebsd-cross-build's Introduction

freebsd-cross-build

Git commits Docker pulls Docker image size (v11.4)

Docker image to enable C/C++ cross-compilation targeting FreeBSD 11.4 from a Linux host. In addition to FreeBSD sysroots, the Alpine 3.18-based image contains Clang v16, GCC (a dependency of Clang in Alpine; provides ar and ranlib), LLD (the LLVM linker), GNU Make, file, and the usual BusyBox shell environment. Compared with other public and published containers, it provides

  • working unprivileged compilation (docker run --user ...),
  • target support for x86_64, arm64, and i386 (targets x86_64-freebsd11, arm64-freebsd11, and , i386-freebsd11, respectively),
  • intact termios headers, and
  • a competitive image size.

This work is based largely on Marco Cilloni's notes.

A previous version of this image targeting FreeBSD 9.3 on x86_64 and i386 with a custom GCC build (still available on the 9.3 Git branch/container image tag) was based based on Marcelo Gornstein's tutorial and the SpectraLogic container.

Usage

$ docker run --rm \
             --user $(id --user):$(id --group) \
             --volume /absolute/path/to/some/source:/workdir \
             empterdose/freebsd-cross-build:11.4 \
             settarget x86_64-freebsd11 make

The container's working directory is /workdir. If you mount your source directory onto this path, you can use relative paths in your build commands.

By default, the container overrides none of Make's implicit variables, and the unprefixed compiler tools on the PATH (clang, clang++, etc.) target x86_64 Linux. Do not use these or the included GCC: they will not produce FreeBSD binaries! To build for FreeBSD, either specifically invoke the prefixed utilities:

$ docker run ... i386-freebsd11-clang -c -o foo.o foo.c

or use the settarget utility to launch a subshell with environment variables (including the PATH) set up for a particular target:

$ docker run --name build \
             --volume $(pwd):/workdir
             --tty \
             --detach \
             empterdose/freebsd-cross-build:11.4
# Build for 64-bit.
$ docker exec build settarget x86_64-freebsd11 make
# Do something to archive the build output.
# `make(1)` is not target-specific.
$ docker exec build make clean
# Build for 32-bit.
$ docker exec build settarget i386-freebsd11 make
# Put our toys away.
$ docker stop build

The image is based on Alpine Linux, so any additional packages you might need can be installed via apk. Note that the image includes GNU Make, not BSD Make.

Dockerfile parameters

The Docker build is parameterized to support variation of the output without actual modification to the Dockerfile. When building the container with docker build, any of these parameters may be passed via --build-arg; or, when building via make, they may be passed as environment variables. When using Make, due to limitations inherent to Make's string handling, spaces in environment variable values will likely cause your computer to catch fire.

  • ALPINE_VERSION: The version of Alpine Linux on which to base the image. (default: 3.18)
  • FBSD_VERSION: The version of FreeBSD to target. (default: 11.4)
  • FBSD_MIRROR: The mirror site/URL prefix for FreeBSD downloads. (default: https://archive.freebsd.org/old-releases)
  • FBSD_AMD64_BASE_URL: The URL for the FreeBSD base.txz archive for the architecture that FreeBSD calls amd64 (what many Linuxes call x86_64). (default: ${FBSD_MIRROR}/amd64/${FBSD_VERSION}-RELEASE/base.txz)
  • FBSD_ARM64_BASE_URL: The URL for the FreeBSD base.txz archive for the arm64 architecture. (default: ${FBSD_MIRROR}/arm64/${FBSD_VERSION}-RELEASE/base.txz)
  • FBSD_I386_BASE_URL: The URL for the FreeBSD base.txz archive for the i386 architecture. (default: ${FBSD_MIRROR}/i386/${FBSD_VERSION}-RELEASE/base.txz)

freebsd-cross-build's People

Contributors

mrdos avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

freebsd-cross-build's Issues

Missing qualified binutils in 11.4

I didn't install the full llvm16 package in the 11.4 image, and didn't symlink its binutils equivalents to qualified names. Specifically, the 9.3 image has qualified instances of:

  • addr2line
  • ar
  • as
  • c++
  • c++filt
  • cpp
  • g++
  • gcc
  • gcc-4.2.4
  • gccbug
  • gcov
  • gprof
  • ld
  • nm
  • objcopy
  • objdump
  • ranlib
  • readelf
  • size
  • strings
  • strip

...whereas the 11.4 images only have qualified names for:

  • c++
  • cc
  • clang
  • clang++
  • clang-cpp
  • cpp
  • ld

I would say the omission of cc from the 9.3 image was an oversight. And some GCC-specific tools (gcc, gcc-4.2.4, gccbug) obviously won't be making a reappearance in the 11.4 image. But I should add qualified, compatible versions of all of the rest, and maybe expand the settarget script to provide the tools by unqualified names, too.

Update to 12.4 with clang

Can this be updated to 12.4 with clang from base? 9.3 is dead for many many years and GCC is not the standard compiler anymore in base.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.