Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Dockerfile.builder
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ RUN apt-get update \

ARG REPO_ROOT

ARG UID=1000
RUN useradd -u ${UID} builder

COPY cmake /${REPO_ROOT}/cmake
COPY scripts /${REPO_ROOT}/scripts
COPY config /${REPO_ROOT}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ Then build the toolchain by running

The build artifact is `./output/llvm-pauth.squashfs` file.

The build scripts try to detect the UID of the real user running `./build.sh`
in case this script is executed with `sudo` to make the contents of `./output`
and `./ccache` directories writable without `sudo` by the host user. This is
especially useful to prevent the `host-build` performed with the same `./ccache`
directory from silently falling back to non-cached build.

# Using the toolchain

Mount the produced SquashFS image at `/opt/llvm-pauth`:
Expand Down
12 changes: 12 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,22 @@ build_in_docker() {
check_repo_sha "$ROOT/src/llvm" "$LLVM_SHA"
check_repo_sha "$ROOT/src/musl" "$MUSL_SHA"

# Try creating a non-privileged user inside the container with the same UID
# as the UID of the real user to ensure ./ccache and ./output are writable
# without sudo on the host - this is useful to make sure ccache does not
# silently fall back to non-cached rebuilds in the 'host-build' mode of build.sh.
local UID
if [ "x$SUDO_USER" != "x" ]; then
UID="$(id -u "$SUDO_USER")"
else
UID="$(id -u)"
fi

$DOCKER_CMD build \
-t "$DOCKER_IMAGE_NAME" \
-f Dockerfile.builder \
--build-arg REPO_ROOT="$REPO_ROOT" \
--build-arg UID="$UID" \
"$ROOT"
$DOCKER_CMD run -ti --rm \
--volume "$ROOT/output:$OUTPUT_DIR:rw" \
Expand Down
4 changes: 4 additions & 0 deletions scripts/build-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
set -xe
cd "$(dirname "$0")"

if [ "$1" != "no-switch-user" ]; then
exec su builder -c "$0 no-switch-user"
fi

# This script is an entry point inside the Docker container.
# Its location is expected to be $REPO_ROOT/scripts/build-in-docker.sh.

Expand Down