Skip to content

Commit

Permalink
feat: cross compilation toolchain building script (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
llenotre committed May 7, 2024
1 parent 966c705 commit 2bca9ce
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 32 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/target
toolchain/
*.swp
1 change: 1 addition & 0 deletions cross/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
toolchain/
3 changes: 3 additions & 0 deletions cross/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Cross compilation

This directory contains utilities to build a toolchain to be used to cross-compile packages.
26 changes: 26 additions & 0 deletions cross/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

set -e

# If the target is not specified, set to default
if [ -z $TARGET ]; then
export TARGET=i686-unknown-linux-musl
fi

# Prepare
mkdir -p toolchain/repo
PATH="$(pwd)/../target/release:$PATH"
export SYSROOT="$(pwd)/toolchain/"
export LOCAL_REPO="$(pwd)/toolchain/repo/"

# binutils
blimp-builder desc/binutils toolchain/repo/
yes | blimp install binutils

# musl
source ./env.sh
HOST="$TARGET" blimp-builder desc/musl toolchain/repo/
unset CC LD CFLAGS LDFLAGS RUSTFLAGS
yes | blimp install musl

# TODO clang
20 changes: 20 additions & 0 deletions cross/desc/binutils/build-hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -e
cd *

mkdir build
cd build

# Compile
../configure \
--prefix=/usr \
--build="$BUILD" \
--host="$HOST" \
--target="$TARGET" \
--disable-werror \
--enable-64-bit-bfd
make -j${JOBS}

# Install
make DESTDIR=$SYSROOT install -j1
17 changes: 17 additions & 0 deletions cross/desc/binutils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"sources": [
{
"location": "/",
"url": "https://ftp.gnu.org/gnu/binutils/binutils-2.42.tar.gz"
}
],
"package": {
"name": "binutils",
"version": "2.42",

"description": "The GNU Binutils are a collection of binary tools.",

"build_deps": [],
"run_deps": []
}
}
17 changes: 17 additions & 0 deletions cross/desc/musl/build-hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e
cd *

# Compile
./configure \
--build="$BUILD" \
--host="$HOST" \
--target="$TARGET" \
--prefix="/usr" \
--enable-optimize \
--enable-shared
make -j${JOBS}

# Install
make DESTDIR=$SYSROOT install
17 changes: 17 additions & 0 deletions cross/desc/musl/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"sources": [
{
"location": "/",
"url": "https://musl.libc.org/releases/musl-1.2.5.tar.gz"
}
],
"package": {
"name": "musl",
"version": "1.2.5",

"description": "musl is an implementation of the C standard library built on top of the Linux system call API, including interfaces defined in the base language standard, POSIX, and widely agreed-upon extensions.",

"build_deps": [],
"run_deps": []
}
}
11 changes: 5 additions & 6 deletions scripts/cross_compile_env.sh → cross/env.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# This file contains an environment to cross-compile packages to the i686 architecture
# The script requires the TOOLCHAIN variable to be set to the toolchain's path
# Usage: `source env.sh`
# `TARGET` is the target triplet for the compiler

# If the target is not specified, set to default
if [ -z $TARGET ]; then
export TARGET=i686-unknown-linux-musl
fi
TOOLCHAIN="$(pwd)/toolchain"

export PATH="$TOOLCHAIN/usr/bin:$TOOLCHAIN/toolchain/bin:$PATH"

export CC="clang"
export LD="ld.lld"
Expand Down
25 changes: 0 additions & 25 deletions scripts/build_toolchain.sh

This file was deleted.

0 comments on commit 2bca9ce

Please sign in to comment.