Skip to content
Snippets Groups Projects
Commit 12450142 authored by test_nonet's avatar test_nonet
Browse files

clean up and add config for canadian cross builds

parent 4abbc8e6
No related branches found
No related tags found
No related merge requests found
CT_TOOLCHAIN_TYPE="canadian"
CT_BUILD="x86_64-unknown-linux-gnu"
#CT_BUILD_PREFIX="x86_64-unknown-linux-gnu-"
CT_BUILD_PREFIX="x86_64-unknown-linux-gnu-wrapped-"
CT_HOST="aarch64-unknown-linux-gnu"
CT_HOST_PREFIX="aarch64-unknown-linux-gnu-"
unset CT_CROSS
CT_CANADIAN=y
CT_HOST_SUFFIX=
#CT_CC_CORE_PASSES_NEEDED=y
#CT_CC_CORE_PASS_1_NEEDED=y
#CT_CC_GCC_STATIC_LIBSTDCXX=y
......@@ -8,6 +8,14 @@ let
ln -s ${pkg}/bin/gcc $out/bin/${pkg.stdenv.targetPlatform.config}-gcc
ln -s ${pkg}/bin/gcc $out/bin/${pkg.stdenv.targetPlatform.config}-wrapped-gcc
'';
# If Nix is cross-compiling this package, we have build!=host!=target (but Nix doesn't know about target, which is ESP32).
# This is called "canadian cross" for GCC builds and it needs some special care with crosstool-NG:
# 1. We need a working compiler for build-build. We cannot simply use the prefixed gcc name because that would
# directly go to the gcc binary and skip the wrapper script. We create a prefixed variant of the wrapper script
# with `wrapIt` and add this to depsBuildBuild.
# 2. We must tell crosstool-NG that we are building a canadian cross.
canadian = stdenv.buildPlatform != stdenv.hostPlatform;
in stdenv.mkDerivation {
pname = "espressif-esp32-tools";
inherit (srcs) version srcs;
......@@ -16,10 +24,9 @@ in stdenv.mkDerivation {
(lib.attrsets.mapAttrsToList (name: drv: if drv ? outPath then "${name} ${drv.outPath}" else "") srcs2);
buildInputs = [ ncurses python3 ];
depsBuildBuild = [ gcc binutils (wrapIt gcc.__spliced.buildBuild) ];
depsBuildBuild = if canadian then [ gcc binutils (wrapIt gcc.__spliced.buildBuild) ] else [ ];
nativeBuildInputs = [ espressif-crosstool-ng autoconf automake bison flex unzip help2man libtool which texinfo file wget gnum4 perl python3 ]
++ [ breakpointHook ];
# ++ [ (wrapIt gcc.__spliced.buildTarget) ];
hardeningDisable = [ "format" "pie" ];
......@@ -45,13 +52,18 @@ in stdenv.mkDerivation {
echo "CT_LOCAL_TARBALLS_DIR=$PWD/tarballs" >>.config
echo "CT_FORBID_DOWNLOAD=y" >>.config
sed -nE 's/^(.*-)g?cc$/CT_BUILD_PREFIX="\1"/p' <<<"$OLD_CC" >>.config
'';
#FIXME for cross-compiling
# cat ../../canadian.txt >>.config
# yes "" | ct-ng oldconfig
'' + (if !canadian then "" else ''
cat >>.config <<EOF
CT_TOOLCHAIN_TYPE="canadian"
unset CT_CROSS
CT_CANADIAN=y
CT_BUILD="${stdenv.buildPlatform.config}"
CT_BUILD_PREFIX="${stdenv.buildPlatform.config}-wrapped-"
CT_HOST="${stdenv.hostPlatform.config}"
CT_HOST_PREFIX="${stdenv.hostPlatform.config}-"
EOF
( yes "" || true ) | ct-ng oldconfig
'');
buildPhase = ''
export CT_USE_SOURCES_FROM_NIXOS=y
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment