mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-23 22:51:03 +02:00
add(build_toolchains): New command to build cross and native target toolchains.
This replaces the cross-toolchain compile step in bootstrap_sdk and adds the ability to build native toolchains using the cross toolchain. This is just the first step towards actually providing the native toolchain in a container.
This commit is contained in:
parent
5d8237b2c6
commit
c503b0248b
136
build_library/catalyst_toolchains.sh
Normal file
136
build_library/catalyst_toolchains.sh
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
source /tmp/chroot-functions.sh
|
||||||
|
source /tmp/toolchain_util.sh
|
||||||
|
|
||||||
|
# A note on packages:
|
||||||
|
# The default PKGDIR is /usr/portage/packages
|
||||||
|
# To make sure things are uploaded to the correct places we split things up:
|
||||||
|
# crossdev build packages use ${PKGDIR}/crossdev (uploaded to SDK location)
|
||||||
|
# build deps in crossdev's sysroot use ${PKGDIR}/cross/${CHOST} (no upload)
|
||||||
|
# native toolchains use ${PKGDIR}/native/${BOARD} (uploaded to board location)
|
||||||
|
|
||||||
|
get_dependency_list() {
|
||||||
|
local ROOT="$1"
|
||||||
|
local IFS=$'| \t\n'
|
||||||
|
shift
|
||||||
|
|
||||||
|
PORTAGE_CONFIGROOT="$ROOT" SYSROOT="$ROOT" \
|
||||||
|
ROOT="$ROOT" emerge ${clst_myemergeopts} \
|
||||||
|
--pretend --with-bdeps=y --onlydeps --quiet \
|
||||||
|
"$@" | sed -e 's/.*\] \([^ :]*\).*/=\1/' |
|
||||||
|
egrep -v "(=$(echo "$*")-[0-9])"
|
||||||
|
}
|
||||||
|
|
||||||
|
configure_portage() {
|
||||||
|
local pkg_path="$1"
|
||||||
|
mkdir -p "${ROOT}/etc/portage"
|
||||||
|
rm -f "${ROOT}/etc/make.profile" "${ROOT}/etc/portage/make.profile"
|
||||||
|
# eselect will report "!!! Warning: Strange path." but that's OK
|
||||||
|
eselect profile set --force coreos:coreos/amd64/generic
|
||||||
|
cat >"${ROOT}/etc/portage/make.conf" <<EOF
|
||||||
|
CHOST=${CHOST}
|
||||||
|
CBUILD=$(portageq envvar CBUILD)
|
||||||
|
HOSTCC=\${CBUILD}-gcc
|
||||||
|
ROOT="${ROOT}"
|
||||||
|
SYSROOT="${SYSROOT}"
|
||||||
|
PKG_CONFIG_PATH="\${SYSROOT}/usr/lib/pkgconfig/"
|
||||||
|
PORTDIR="$(portageq envvar PORTDIR)"
|
||||||
|
DISTDIR="\${PORTDIR}/distfiles"
|
||||||
|
PKGDIR="\${PORTDIR}/packages/${pkg_path}"
|
||||||
|
PORTDIR_OVERLAY="$(portageq envvar PORTDIR_OVERLAY)"
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
build_cross_toolchain() {
|
||||||
|
local cross_chost="$1"
|
||||||
|
local cross_pkgs=( "${TOOLCHAIN_PKGS[@]/*\//cross-${cross_chost}/}" )
|
||||||
|
local PORTDIR="$(portageq envvar PORTDIR)"
|
||||||
|
local PKGDIR="${PORTDIR}/packages/crossdev"
|
||||||
|
|
||||||
|
PKGDIR="${PKGDIR}" crossdev \
|
||||||
|
--ov-output "/tmp/crossdev" --stable \
|
||||||
|
--portage "${clst_myemergeopts}" \
|
||||||
|
--init-target --target "${cross_chost}"
|
||||||
|
|
||||||
|
# If PKGCACHE is enabled check to see if binary packages are available.
|
||||||
|
# If so then don't perform a full bootstrap and just call emerge instead.
|
||||||
|
if [[ -n "${clst_PKGCACHE}" ]] && \
|
||||||
|
PKGDIR="${PKGDIR}" emerge ${clst_myemergeopts} \
|
||||||
|
--usepkgonly --binpkg-respect-use=y \
|
||||||
|
--pretend "${cross_pkgs[@]}" &>/dev/null
|
||||||
|
then
|
||||||
|
PKGDIR="${PKGDIR}" run_merge -u "${cross_pkgs[@]}"
|
||||||
|
else
|
||||||
|
PKGDIR="${PKGDIR}" crossdev \
|
||||||
|
--ov-output "/tmp/crossdev" --stable \
|
||||||
|
--env PKGDIR="${PORTDIR}/packages/crossdev" \
|
||||||
|
--portage "${clst_myemergeopts}" \
|
||||||
|
--stage4 --target "${cross_chost}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Setup ccache for our shiny new toolchain
|
||||||
|
ccache-config --install-links "${cross_chost}"
|
||||||
|
}
|
||||||
|
|
||||||
|
configure_cross_root() {
|
||||||
|
local cross_chost="$1"
|
||||||
|
local ROOT="/usr/${cross_chost}"
|
||||||
|
|
||||||
|
CHOST="${cross_chost}" ROOT="$ROOT" SYSROOT="$ROOT" \
|
||||||
|
configure_portage "cross/${cross_chost}"
|
||||||
|
|
||||||
|
# In order to get a dependency list we must calculate it before
|
||||||
|
# updating package.provided. Otherwise portage will no-op.
|
||||||
|
get_dependency_list "$ROOT" "${TOOLCHAIN_PKGS[@]}" \
|
||||||
|
> "$ROOT/etc/portage/cross-${cross_chost}-depends"
|
||||||
|
|
||||||
|
# Add toolchain to packages.provided since they are on the host system
|
||||||
|
mkdir -p "$ROOT/etc/portage/profile/package.provided"
|
||||||
|
local native_pkg cross_pkg cross_pkg_version
|
||||||
|
for native_pkg in "${TOOLCHAIN_PKGS[@]}"; do
|
||||||
|
cross_pkg="${native_pkg/*\//cross-${cross_chost}/}"
|
||||||
|
cross_pkg_version=$(portageq match / "${cross_pkg}")
|
||||||
|
echo "${native_pkg%/*}/${cross_pkg_version#*/}"
|
||||||
|
done > "$ROOT/etc/portage/profile/package.provided/cross-${cross_chost}"
|
||||||
|
}
|
||||||
|
|
||||||
|
build_cross_libs() {
|
||||||
|
local cross_chost="$1"
|
||||||
|
local ROOT="/usr/${cross_chost}"
|
||||||
|
local cross_deps=$(<"$ROOT/etc/portage/cross-${cross_chost}-depends")
|
||||||
|
|
||||||
|
# --root is required because run_merge overrides ROOT=
|
||||||
|
PORTAGE_CONFIGROOT="$ROOT" run_merge -u --root="$ROOT" $cross_deps
|
||||||
|
}
|
||||||
|
|
||||||
|
configure_target_root() {
|
||||||
|
local board="$1"
|
||||||
|
local cross_chost=$(get_board_chost "$1")
|
||||||
|
|
||||||
|
CHOST="${cross_chost}" ROOT="/build/${board}" \
|
||||||
|
SYSROOT="/usr/${cross_chost}" configure_portage "target/${board}"
|
||||||
|
}
|
||||||
|
|
||||||
|
build_target_toolchain() {
|
||||||
|
local board="$1"
|
||||||
|
local ROOT="/build/${board}"
|
||||||
|
|
||||||
|
# --root is required because run_merge overrides ROOT=
|
||||||
|
PORTAGE_CONFIGROOT="$ROOT" \
|
||||||
|
run_merge -u --root="$ROOT" "${TOOLCHAIN_PKGS[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
for cross_chost in $(get_chost_list); do
|
||||||
|
echo "Building cross toolchain for ${cross_chost}"
|
||||||
|
build_cross_toolchain "${cross_chost}"
|
||||||
|
configure_cross_root "${cross_chost}"
|
||||||
|
build_cross_libs "${cross_chost}"
|
||||||
|
done
|
||||||
|
|
||||||
|
for board in $(get_board_list); do
|
||||||
|
echo "Building native toolchain for ${bard}"
|
||||||
|
configure_target_root "${board}"
|
||||||
|
build_target_toolchain "${board}"
|
||||||
|
done
|
50
build_library/toolchain_util.sh
Normal file
50
build_library/toolchain_util.sh
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Toolchain packages are treated a bit specially, since they take a
|
||||||
|
# while to build and are generally more complicated to build they are
|
||||||
|
# only built via catalyst and everyone else installs them as binpkgs.
|
||||||
|
TOOLCHAIN_PKGS=(
|
||||||
|
sys-devel/binutils
|
||||||
|
sys-devel/gcc
|
||||||
|
sys-kernel/linux-headers
|
||||||
|
sys-libs/glibc
|
||||||
|
)
|
||||||
|
|
||||||
|
# Map board names to CHOSTs and portage profiles. This is the
|
||||||
|
# definitive list, there is assorted code new and old that either
|
||||||
|
# guesses or hard-code these. All that should migrate to this list.
|
||||||
|
declare -A BOARD_CHOST BOARD_PROFILE
|
||||||
|
BOARD_CHOST["amd64-generic"]="x86_64-cros-linux-gnu"
|
||||||
|
BOARD_PROFILE["amd64-generic"]="coreos:coreos/amd64/generic"
|
||||||
|
BOARD_NAMES=( "${!BOARD_CHOST[@]}" )
|
||||||
|
|
||||||
|
get_board_list() {
|
||||||
|
local IFS=$'\n\t '
|
||||||
|
sort <<<"${BOARD_NAMES[*]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_chost_list() {
|
||||||
|
local IFS=$'\n\t '
|
||||||
|
sort -u <<<"${BOARD_CHOST[*]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_profile_list() {
|
||||||
|
local IFS=$'\n\t '
|
||||||
|
sort -u <<<"${BOARD_PROFILE[*]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_board_chost() {
|
||||||
|
if [[ ${#BOARD_CHOST["$1"]} -ne 0 ]]; then
|
||||||
|
echo "${BOARD_CHOST["$1"]}"
|
||||||
|
else
|
||||||
|
die "Unknown board '$1'"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
get_board_profile() {
|
||||||
|
if [[ ${#BOARD_PROFILE["$1"]} -ne 0 ]]; then
|
||||||
|
echo "${BOARD_PROFILE["$1"]}"
|
||||||
|
else
|
||||||
|
die "Unknown board '$1'"
|
||||||
|
fi
|
||||||
|
}
|
54
build_toolchains
Executable file
54
build_toolchains
Executable file
@ -0,0 +1,54 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Copyright (c) 2013 The CoreOS Authors. All rights reserved.
|
||||||
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
|
# found in the LICENSE file.
|
||||||
|
|
||||||
|
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
|
||||||
|
. "${SCRIPT_ROOT}/common.sh" || exit 1
|
||||||
|
|
||||||
|
TYPE="coreos-toolchains"
|
||||||
|
ARCH=$(portageq envvar ARCH)
|
||||||
|
DEFAULT_SEED="builds/coreos-sdk/stage4-${ARCH}-latest.tar.bz2"
|
||||||
|
DEFAULT_PROFILE="coreos:default/linux/${ARCH}/10.0"
|
||||||
|
FORCE_STAGES="stage4"
|
||||||
|
|
||||||
|
. "${BUILD_LIBRARY_DIR}/catalyst.sh" || exit 1
|
||||||
|
. "${BUILD_LIBRARY_DIR}/toolchain_util.sh" || exit 1
|
||||||
|
|
||||||
|
# include upload options
|
||||||
|
. "${BUILD_LIBRARY_DIR}/release_util.sh" || exit 1
|
||||||
|
|
||||||
|
ROOT_OVERLAY="${TEMPDIR}/stage4-${ARCH}-$FLAGS_version-overlay"
|
||||||
|
|
||||||
|
## Define the stage4 config template
|
||||||
|
catalyst_stage4() {
|
||||||
|
cat <<EOF
|
||||||
|
target: stage4
|
||||||
|
pkgcache_path: $BINPKGS
|
||||||
|
stage4/packages: @system
|
||||||
|
stage4/fsscript: ${BUILD_LIBRARY_DIR}/catalyst_toolchains.sh
|
||||||
|
stage4/root_overlay: ${ROOT_OVERLAY}
|
||||||
|
EOF
|
||||||
|
catalyst_stage_default
|
||||||
|
}
|
||||||
|
|
||||||
|
catalyst_init "$@"
|
||||||
|
check_gsutil_opts
|
||||||
|
|
||||||
|
# toolchain_util.sh is required by catalyst_toolchains.sh
|
||||||
|
mkdir -p "${ROOT_OVERLAY}/tmp"
|
||||||
|
cp "${BUILD_LIBRARY_DIR}/toolchain_util.sh" "${ROOT_OVERLAY}/tmp"
|
||||||
|
|
||||||
|
catalyst_build
|
||||||
|
|
||||||
|
def_upload_path="${UPLOAD_ROOT}/sdk/${ARCH}/${FLAGS_version}"
|
||||||
|
upload_files "packages" "${def_upload_path}" "pkgs/" "${BINPKGS}/crossdev"/*
|
||||||
|
|
||||||
|
for board in $(get_board_list); do
|
||||||
|
board_packages="${BINPKGS}/target/${board}"
|
||||||
|
def_upload_path="${UPLOAD_ROOT}/${board}/${FLAGS_version}"
|
||||||
|
upload_files packages "${def_upload_path}" "pkgs/" "${board_packages}"/*
|
||||||
|
done
|
||||||
|
|
||||||
|
command_completed
|
Loading…
x
Reference in New Issue
Block a user