Skip to content

Commit

Permalink
Add rust std lib cross-build
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalmiel committed May 13, 2024
1 parent 08eacea commit 1b088c9
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
63 changes: 61 additions & 2 deletions sysroot/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CYKUSZ_DIR=$(realpath $SPATH/..)
SRC_DIR=$CYKUSZ_DIR/sysroot/src
BINUTILS_SRC_DIR=$SRC_DIR/binutils-gdb
GCC_SRC_DIR=$SRC_DIR/gcc
RUST_SRC_DIR=$HOME/rust
LIBTOOL_SRC_DIR=$SRC_DIR/libtool
MLIBC_SRC_DIR=$SRC_DIR/mlibc
NYANCAT_SRC_DIR=$SRC_DIR/nyancat
Expand Down Expand Up @@ -63,6 +64,7 @@ LIBIDN2_CYKUSZ_BUILD_DIR=$BUILD_DIR/cykusz-libidn2
LIBFFI_CYKUSZ_BUILD_DIR=$BUILD_DIR/cykusz-libffi
LIBEXPAT_CYKUSZ_BUILD_DIR=$BUILD_DIR/cykusz-libexpat
GCC_BUILD_DIR=$BUILD_DIR/gcc
RUST_BUILD_DIR=$HOME/build-rust
MLIBC_BUILD_DIR=$BUILD_DIR/mlibc

SYSROOT=$CYKUSZ_DIR/sysroot/cykusz
Expand Down Expand Up @@ -103,6 +105,45 @@ function _prepare_gcc {
fi
}

function _prepare_rust {
if [ ! -d $RUST_SRC_DIR ]; then
mkdir -p $SRC_DIR
git clone --depth 1 -b cykusz https://github.com/rafalmiel/rust.git $RUST_SRC_DIR

pushd .

cd $RUST_SRC_DIR
cat > config.toml <<EOL
change-id = 124501
[llvm]
download-ci-llvm = false
targets = "X86"
[build]
target = ["x86_64-unknown-cykusz", "x86_64-unknown-linux-gnu"]
build-dir = "$RUST_BUILD_DIR"
docs = false
[install]
prefix = ""
sysconfdir = "etc"
[rust]
codegen-tests = false
deny-warnings = false # work around rust-num-cpus warning
[target.x86_64-unknown-linux-gnu]
llvm-config = "$CROSS/bin/llvm-config"
[target.x86_64-unknown-cykusz]
llvm-config = "$CROSS/bin/llvm-config"
EOL

popd
fi
}

function _prepare_libtool {
if [ ! -d $LIBTOOL_SRC_DIR ]; then
mkdir -p $SRC_DIR
Expand Down Expand Up @@ -448,6 +489,24 @@ function _gcc {
make -C $GCC_BUILD_DIR install-gcc
}

function _rust {
_prepare_rust

pushd .

cd $RUST_SRC_DIR
CARGO_HOME=/tmp/cargo-home
mkdir -p $CARGO_HOME

cp $SPATH/cfg/rust/host-config.toml $CARGO_HOME/config.toml

rustup component add rust-src
CARGO_HOME=$CARGO_HOME ./x.py build --stage 2 -j12 --verbose
CARGO_HOME=$CARGO_HOME DESTDIR=$CROSS ./x.py install

popd
}

function _llvm {
_prepare_llvm

Expand Down Expand Up @@ -979,8 +1038,8 @@ function _cykusz_readline {
}

function _cykusz_apps {
$TRIPLE-gcc $SRC_DIR/cykusz_apps/test.c -o $BUILD_DIR/test
$TRIPLE-gcc $SRC_DIR/cykusz_apps/stack.c -o $BUILD_DIR/stack
clang $SRC_DIR/cykusz_apps/test.c -o $BUILD_DIR/test
clang $SRC_DIR/cykusz_apps/stack.c -o $BUILD_DIR/stack
$TRIPLE-g++ $SRC_DIR/cykusz_apps/hello.cpp -o $BUILD_DIR/hello
$TRIPLE-g++ $SRC_DIR/cykusz_apps/test.cpp -o $BUILD_DIR/testcpp
$TRIPLE-gcc $SRC_DIR/cykusz_apps/ttytest.c -o $BUILD_DIR/ttytest
Expand Down
15 changes: 14 additions & 1 deletion sysroot/cfg/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
FROM ubuntu:jammy

ARG uid=1000
ARG gid=1000

RUN addgroup --gid "$gid" ck
RUN adduser --uid "$uid" --gid "$gid" --gecos "" --disabled-password ck

RUN apt-get update
RUN apt-get -y install nasm meson ninja-build bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo xorriso autotools-dev automake autoconf autoconf-archive gettext pkgconf autopoint gcc-12 g++-12 gperf linux-libc-dev python3.11 groff gengetopt cmake git rsync wget help2man
RUN apt-get -y install curl nasm meson ninja-build bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo xorriso autotools-dev automake autoconf autoconf-archive gettext pkgconf autopoint gcc-12 g++-12 gperf linux-libc-dev python3.11 groff gengetopt cmake git rsync wget help2man
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12
RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 12

USER ck

RUN mkdir -p /home/ck/cykusz-rs
WORKDIR /home/ck/cykusz-rs/sysroot

RUN curl https://sh.rustup.rs -sSf | \
sh -s -- -y

ENV PATH=/home/ck/.cargo/bin:$PATH

CMD ["bash"]
2 changes: 1 addition & 1 deletion sysroot/make_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
SPATH=$(dirname $(readlink -f "$0"))
CYKUSZ_DIR=$(realpath $SPATH/..)

docker buildx build -t cykusz-build $CYKUSZ_DIR/sysroot/cfg/docker
docker buildx build -t cykusz-build --build-arg uid=$(id -u) --build-arg gid=$(id -g) $CYKUSZ_DIR/sysroot/cfg/docker

0 comments on commit 1b088c9

Please sign in to comment.