Skip to content

Commit

Permalink
add Ubuntu builder image & fix v8 build
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Baccini <giuseppe.baccini@logobject.ch>
  • Loading branch information
giubacc committed Apr 9, 2024
1 parent c277abb commit bfe5ef7
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_dispatch: # Allow this workflow to be triggered manually

env:
IMAGE_NAME_BUILDER: chatterbox-builder
IMAGE_NAME_BUILDER: chatterbox-ubuntu-builder

jobs:
build-and-push-builder:
Expand All @@ -30,7 +30,7 @@ jobs:
- name: Build and push builder-image
uses: docker/build-push-action@v3
with:
file: 'scripts/Dockerfile.builder'
file: 'scripts/Dockerfile-ubuntu.builder'
context: scripts
push: true
tags: ghcr.io/${{ github.actor }}/${{ env.IMAGE_NAME_BUILDER }}:latest
Expand Down
2 changes: 1 addition & 1 deletion contrib/depot_tools
Submodule depot_tools updated from 9c44fe to a5c46d
22 changes: 11 additions & 11 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- [Build](#build)
- [Build requirements](#build-requirements)
- [How to build](#how-to-build)
- [Build using the OpenSuse Leap Docker builder image](#build-using-the-opensuse-leap-docker-builder-image)
- [Build using a Docker builder image](#build-using-a-docker-builder-image)

## Build requirements

Expand All @@ -12,15 +12,14 @@ Currently, `chatterbox` can be solely built under Linux.
If you wish to build the `chatterbox` binary directly on your Linux
distribution, ensure your system provides all the required dependencies.
You can figure out what are the needed packages for your system by inspecting the
[builder Dockerfile](../scripts/Dockerfile.builder) for OpenSuse Tumbleweed.
[builder Dockerfile](../scripts/Dockerfile-leap.builder) for OpenSuse Tumbleweed.

## How to build

After you have checked out all the `chatterbox`'s submodules with:

```shell
git submodule init
git submodule update
git submodule update --init --recursive
```

Build the `chatterbox` binary, alongside with all its dependencies, with:
Expand All @@ -30,15 +29,16 @@ cd scripts
./build.sh build-all
```

### Build using the OpenSuse Leap Docker builder image
### Build using a Docker builder image

It is possible to use a Docker builder image to compile the binary
of `chatterbox`.

- `scripts/Dockerfile.builder`
- `scripts/Dockerfile-leap.builder`
- `scripts/Dockerfile-ubuntu.builder`

To build `chatterbox` with the Docker builder image, your system needs
to provide Podman or Docker.
to provide Docker.

To create the `chatterbox` builder image:

Expand All @@ -50,12 +50,12 @@ cd scripts
```shell
$ docker images

REPOSITORY TAG
localhost/chatterbox-builder latest
REPOSITORY TAG
localhost/chatterbox-ubuntu-builder latest
```

Using this image, it is possible to build the `chatterbox` binary
for OpenSuse Leap:
Using the image, it is possible to build the `chatterbox` binary
for the target system:

```shell
cd scripts
Expand Down
14 changes: 8 additions & 6 deletions scripts/Dockerfile.builder → scripts/Dockerfile-leap.builder
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ RUN zypper -n install --no-recommends \
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12 \
&& update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-12 12 \
&& update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 12 \
&& update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-12 12
&& update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-12 12 \
&& update-alternatives --install /usr/bin/python3 python /usr/bin/python3.11 311

RUN mkdir -p /project/contrib
ENV CONTRIB_PATH /project/contrib
ENV TAR_OPTIONS --no-same-owner

COPY contrib_init.sh /usr/bin/contrib_init.sh
COPY rapidyaml-build /contrib/rapidyaml-build
COPY rapidyaml-build /project/contrib/rapidyaml-build
COPY build.sh /usr/bin/build.sh

ENV CONTRIB_PATH /contrib
ENV TAR_OPTIONS --no-same-owner
RUN contrib_init.sh && build.sh build-deps \
&& find /contrib -name "*.o" -type f -delete \
&& find /contrib -name "*.so" -type f -delete \
Expand All @@ -47,7 +49,7 @@ RUN contrib_init.sh && build.sh build-deps \
&& cp -R --parents /contrib/v8/include /tmp \
&& cp -R --parents /contrib/googletest/googletest/include /tmp \
&& cp -R --parents /contrib/restclient-cpp/.libs /tmp \
&& cp -R --parents /contrib/v8/out/x86.release/obj /tmp \
&& cp -R --parents /contrib/v8/out/x64.release/obj /tmp \
&& cp -R --parents /contrib/googletest/build/lib /tmp \
&& rm -rf /contrib \
&& mv /tmp/contrib /contrib
Expand Down
48 changes: 48 additions & 0 deletions scripts/Dockerfile-ubuntu.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FROM ubuntu:22.04
LABEL Name=chatterbox-builder

RUN apt-get update && apt-get -y install \
build-essential \
ninja-build \
wget \
make \
cmake \
git \
python3 \
python3-venv \
libglib2.0-dev \
automake \
autogen \
libssl-dev \
libcurl4-openssl-dev \
&& apt-get autoremove

RUN mkdir -p /project/contrib
ENV CONTRIB_PATH /project/contrib
ENV TAR_OPTIONS --no-same-owner

COPY contrib_init.sh /usr/bin/contrib_init.sh
COPY rapidyaml-build /project/contrib/rapidyaml-build
COPY build.sh /usr/bin/build.sh

RUN contrib_init.sh && build.sh build-deps \
&& find /contrib -name "*.o" -type f -delete \
&& find /contrib -name "*.so" -type f -delete \
&& find /contrib -name "*.exe" -type f -delete \
&& cp -R --parents /contrib/rapidyaml-build /tmp \
&& cp -R --parents /contrib/pistache/include /tmp \
&& cp -R --parents /contrib/pistache/build/src /tmp \
&& cp -R --parents /contrib/restclient-cpp/include /tmp \
&& cp -R --parents /contrib/cryptopp /tmp \
&& cp -R --parents /contrib/spdlog/include /tmp \
&& cp -R --parents /contrib/clipp/include /tmp \
&& cp -R --parents /contrib/v8/include /tmp \
&& cp -R --parents /contrib/googletest/googletest/include /tmp \
&& cp -R --parents /contrib/restclient-cpp/.libs /tmp \
&& cp -R --parents /contrib/v8/out/x64.release/obj /tmp \
&& cp -R --parents /contrib/googletest/build/lib /tmp \
&& rm -rf /contrib \
&& mv /tmp/contrib /contrib

ENTRYPOINT ["build.sh"]
CMD ["build"]
18 changes: 10 additions & 8 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
container_mng=${CNT_MNG:-"docker"}
basedir=$(realpath ${BASE_DIR:-"../"})
ninja_jobs=${NINJA_JOBS:-"6"}
builder_image=${BUILDER_IMAGE:-"chatterbox-builder"}
builder_image=${BUILDER_IMAGE:-"chatterbox-ubuntu-builder"}
builder_dockerfile=${BUILDER_DOCKERFILE:-"Dockerfile-ubuntu.builder"}
contrib_path=$(realpath ${CONTRIB_PATH:-"../contrib"})
python_bin=${PYTHON_BIN:-"python3.11"}
python_bin=${PYTHON_BIN:-"python3"}

usage() {
cat << EOF
Expand Down Expand Up @@ -35,6 +36,7 @@ env variables
BASE_DIR Specify the directory containing src and test directories (default: ../).
NINJA_JOBS Specify the number of parallel ninja jobs.
BUILDER_IMAGE Specify the builder's image to use.
BUILDER_DOCKERFILE Specify the builder's dockerfile to use.
CONTRIB_PATH Specify the path where contrib resources are placed.
EOF
}
Expand All @@ -45,8 +47,8 @@ error() {

create_builder() {
echo "Creating the chatterbox builder image ..."
$container_mng build -t chatterbox-builder \
-f Dockerfile.builder . || exit 1
$container_mng build -t ${builder_image} \
-f $builder_dockerfile . || exit 1
}

builder_build() {
Expand Down Expand Up @@ -155,8 +157,8 @@ clean_googletest() {

# see this issue: https://bugs.chromium.org/p/v8/issues/detail?id=13455
patch_v8_code() {
sed -i 's/std::is_pod/std::is_standard_layout/g' $basedir/contrib/v8/src/base/vector.h
sed -i 's/std::back_insert_iterator(snapshots)/std::back_insert_iterator<base::SmallVector<Snapshot, 8>>(snapshots)/g' $basedir/contrib/v8/src/compiler/turboshaft/wasm-gc-type-reducer.cc
sed -i 's/std::is_pod/std::is_standard_layout/g' $contrib_path/v8/src/base/vector.h
sed -i 's/std::back_insert_iterator(snapshots)/std::back_insert_iterator<base::SmallVector<Snapshot, 8>>(snapshots)/g' $contrib_path/v8/src/compiler/turboshaft/wasm-gc-type-reducer.cc
}

build_v8() {
Expand All @@ -181,8 +183,8 @@ EOF
)
patch_v8_code

gn gen out/x86.release --args="${args}"
ninja -j$ninja_jobs -C out/x86.release v8_monolith || exit 1
gn gen out/x64.release --args="${args}"
ninja -j$ninja_jobs -C out/x64.release v8_monolith || exit 1
}

clean_v8() {
Expand Down
2 changes: 1 addition & 1 deletion scripts/contrib_init.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

contrib_path=$(realpath ${CONTRIB_PATH:-"/contrib"})
contrib_path=$(realpath ${CONTRIB_PATH:-"../contrib"})

mkdir -p $contrib_path

Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ link_directories(${CONTRIB_PATH}/restclient-cpp/.libs
${CONTRIB_PATH}/rapidyaml-build/lib
${CONTRIB_PATH}/pistache/build/src
${CONTRIB_PATH}/cryptopp
${CONTRIB_PATH}/v8/out/x86.release/obj)
${CONTRIB_PATH}/v8/out/x64.release/obj)

add_executable(cbx
main.cpp
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ link_directories(${CONTRIB_PATH}/restclient-cpp/.libs
${CONTRIB_PATH}/rapidyaml-build/lib
${CONTRIB_PATH}/pistache/build/src
${CONTRIB_PATH}/cryptopp
${CONTRIB_PATH}/v8/out/x86.release/obj
${CONTRIB_PATH}/v8/out/x64.release/obj
${CONTRIB_PATH}/googletest/build/lib)

add_executable(cbx_test
Expand Down

0 comments on commit bfe5ef7

Please sign in to comment.