forked from auxolotl/labs
Work in progress cross compiler for x86_64. I've managed to get a full x86_64 gcc using the binaries built from foundation, and am working on implementing their builds into tidepool. ### Bootstrapping steps 0) Start with i686 tools (gcc, binutils, musl, etc) 1) Build binutils targeting x86_64-linux 2) Build a minimal gcc cross compiler using the cross binutils. This minimal cross compiler does not have support for libc, so is pretty much only useful for building musl or glibc. 3) Use the minimal cross compiler to build x86_64-linux glibc or musl 4) Now that we have a cross compiler and x86_64-linux libc, we can build gcc for the target architecture! 5) Profit! We can now build anything x86_64 using our gcc compiler! Co-authored-by: Jake Hamilton <jake.hamilton@hey.com> Reviewed-on: auxolotl/labs#8 Reviewed-by: Jake Hamilton <jake.hamilton@hey.com> Co-authored-by: Victor Fuentes <vmfuentes64@gmail.com> Co-committed-by: Victor Fuentes <vmfuentes64@gmail.com>
176 lines
5.9 KiB
Nix
176 lines
5.9 KiB
Nix
{ lib
|
|
, lib'
|
|
, config
|
|
, options
|
|
,
|
|
}:
|
|
let
|
|
inherit (config)
|
|
mirrors
|
|
builders
|
|
# These are the upstream foundational packages exported from the Aux Foundation project.
|
|
|
|
foundation
|
|
packages
|
|
;
|
|
in
|
|
{
|
|
config.packages.foundation.binutils = {
|
|
versions = {
|
|
"latest" =
|
|
{ config }:
|
|
{
|
|
options = {
|
|
src = lib.options.create {
|
|
type = lib.types.derivation;
|
|
description = "Source for the package.";
|
|
};
|
|
};
|
|
|
|
config =
|
|
let
|
|
isBuildBootstrapped = config.platform.build.double == "i686-linux";
|
|
isHostBootstrapped = config.platform.host.double == "i686-linux";
|
|
|
|
isBootstrapped = isBuildBootstrapped && isHostBootstrapped;
|
|
|
|
isCross =
|
|
config.platform.build.double != config.platform.host.double
|
|
&& config.platform.host.double == config.platform.target.double;
|
|
in
|
|
{
|
|
meta = {
|
|
platforms = [
|
|
"i686-linux"
|
|
"x86_64-linux"
|
|
];
|
|
};
|
|
|
|
pname = "binutils";
|
|
version = "2.41";
|
|
|
|
builder = builders.basic;
|
|
|
|
deps = {
|
|
build = {
|
|
only = {
|
|
gcc = lib.modules.when (!isBootstrapped) (
|
|
if isCross then
|
|
packages.foundation.gcc-cross.versions.latest.extend
|
|
{
|
|
platform = lib.modules.override 0 {
|
|
inherit (config.platform) build target;
|
|
host = config.platform.build;
|
|
};
|
|
}
|
|
else
|
|
packages.foundation.gcc.versions.latest
|
|
);
|
|
glibc = lib.modules.when (isCross) (
|
|
packages.foundation.glibc.versions.latest.extend {
|
|
platform = lib.modules.override 0 {
|
|
inherit (config.platform) host target build;
|
|
};
|
|
}
|
|
);
|
|
binutils = lib.modules.when (isCross) (
|
|
packages.foundation.binutils.versions.latest.extend {
|
|
platform = lib.modules.override 0 {
|
|
inherit (config.platform) target build;
|
|
host = config.platform.build;
|
|
};
|
|
}
|
|
);
|
|
};
|
|
};
|
|
};
|
|
|
|
env = {
|
|
PATH = lib.paths.bin (
|
|
lib.lists.when (isBootstrapped) [ foundation.stage2-gcc ]
|
|
++ [
|
|
foundation.stage2-gcc
|
|
foundation.stage2-binutils
|
|
foundation.stage2-gnumake
|
|
foundation.stage2-gnupatch
|
|
foundation.stage2-gnused
|
|
foundation.stage2-gnugrep
|
|
foundation.stage2-gawk
|
|
foundation.stage2-diffutils
|
|
foundation.stage2-findutils
|
|
foundation.stage2-gnutar
|
|
foundation.stage1-xz
|
|
]
|
|
);
|
|
} // (lib.attrs.when (isCross) {
|
|
LDFLAGS_FOR_TARGET = "-B${config.deps.build.only.glibc.package}/lib -L${config.deps.build.only.glibc.package}/lib -I${config.deps.build.only.glibc.package}/include";
|
|
});
|
|
|
|
phases =
|
|
let
|
|
patches = [
|
|
# Make binutils output deterministic by default.
|
|
./patches/deterministic.patch
|
|
];
|
|
|
|
configureFlags =
|
|
lib.lists.when (!isCross) [
|
|
"LDFLAGS=--static"
|
|
]
|
|
++ [
|
|
"--prefix=${builtins.placeholder "out"}"
|
|
"--build=${config.platform.build.triple}"
|
|
"--host=${config.platform.host.triple}"
|
|
"--target=${config.platform.target.triple}"
|
|
|
|
"--with-sysroot=/"
|
|
"--enable-deterministic-archives"
|
|
# depends on bison
|
|
"--disable-gprofng"
|
|
|
|
# Turn on --enable-new-dtags by default to make the linker set
|
|
# RUNPATH instead of RPATH on binaries. This is important because
|
|
# RUNPATH can be overridden using LD_LIBRARY_PATH at runtime.
|
|
"--enable-new-dtags"
|
|
|
|
# By default binutils searches $libdir for libraries. This brings in
|
|
# libbfd and libopcodes into a default visibility. Drop default lib
|
|
# path to force users to declare their use of these libraries.
|
|
"--with-lib-path=:"
|
|
|
|
"--disable-multilib"
|
|
|
|
];
|
|
in
|
|
{
|
|
unpack = ''
|
|
tar xf ${config.src}
|
|
cd binutils-${config.version}
|
|
'';
|
|
|
|
patch = ''
|
|
${lib.strings.concatMapSep "\n" (file: "patch -Np1 -i ${file}") patches}
|
|
'';
|
|
|
|
configure = ''
|
|
bash ./configure ${builtins.concatStringsSep " " configureFlags}
|
|
'';
|
|
|
|
build = ''
|
|
make -j $NIX_BUILD_CORES
|
|
'';
|
|
|
|
install = ''
|
|
make -j $NIX_BUILD_CORES install-strip
|
|
'';
|
|
};
|
|
|
|
src = builtins.fetchurl {
|
|
url = "${mirrors.gnu}/binutils/binutils-${config.version}.tar.xz";
|
|
sha256 = "rppXieI0WeWWBuZxRyPy0//DHAMXQZHvDQFb3wYAdFA=";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}
|