Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build full chromium binary #1

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
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
121 changes: 121 additions & 0 deletions .github/workflows/chromium.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Build Amazon AMI Chromium

on:
push:
tags:
- '*'

env:
ARTIFACT_PATH: /srv/build/chromium
ARTIFACT_NAME: chromium-aws

jobs:
build:
runs-on: chromium-builder

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Prepare Environment
run: |
sudo mkdir -p ${ARTIFACT_PATH}
sudo chown -R $USER:$USER ${ARTIFACT_PATH}
sudo apt-get update
sudo apt-get install -y jq

- name: Extract Short String from versions.json
id: extract_version
run: |
SHORT_STRING=$(jq -r '."'"${GITHUB_REF#refs/tags/v}"'"' versions.json)
if [ "$SHORT_STRING" = "null" ]; then
echo "No matching version found!"
exit 1
fi
echo ::set-output name=short_string::$SHORT_STRING

- name: Run Dockerized Build
run: |
set -e # Exit immediately if a command exits with a non-zero status
cd chromium_build
./build.sh ${{ steps.extract_version.outputs.short_string }} # build the docker image, this includes the deps to build chromium
docker run --name chromium-build-container --privileged chromium-builder build

- name: Extract Artifacts from Docker Container
run: |
docker cp chromium-build-container:${ARTIFACT_PATH}/chromium.br ${ARTIFACT_PATH}/chromium.br
docker cp chromium-build-container:${ARTIFACT_PATH}/swiftshader.tar.br ${ARTIFACT_PATH}/swiftshader.tar.br
docker cp chromium-build-container:${ARTIFACT_PATH}/VERSION ${ARTIFACT_PATH}/VERSION
docker rm chromium-build-container

- name: Archive artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_PATH }}

release:
needs: build
runs-on: ubuntu-latest

permissions:
contents: write
packages: write

steps:
- name: Prepare Environment
run: |
sudo mkdir -p ${ARTIFACT_PATH}
sudo chown -R $USER:$USER ${ARTIFACT_PATH}

- name: Download artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_PATH }}

- name: Get the tag version
id: extract_branch
run: echo ::set-output name=branch::${GITHUB_REF#refs/tags/}

- name: Create Release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.extract_branch.outputs.branch }}
release_name: ${{ steps.extract_branch.outputs.branch }}

- name: Upload Chromium Build Asset
id: upload_chromium_asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.ARTIFACT_PATH }}/chromium.br
asset_name: chromium-build
asset_content_type: application/octet-stream

- name: Upload Swiftshader Asset
id: upload_swiftshader_asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.ARTIFACT_PATH }}/swiftshader.tar.br
asset_name: swiftshader
asset_content_type: application/octet-stream

- name: Upload Chromium Version Asset
id: upload_version_asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.ARTIFACT_PATH }}/VERSION
asset_name: version
asset_content_type: text/plain
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,15 @@ This allows us to get the best compression ratio and faster decompression times.
| `chromium.br` | Brotli | 10 | 36090087 | 34.42 | 73.65% | 0.765s |
| `chromium.br` | Brotli | 11 | 34820408 | **33.21** | **74.58%** | 0.712s |

## Releasing a new version

Tag the commit with the chromium version number, structured like `v#.#.#`. Make sure to have an accompanying absolute chromium revision number in `versions.json` within the repo. The chromium revision will be a bit more specific than the version number, ie. 116.0.0 -> 1160321.

```bash
git tag v116.0.0
git push origin v116.0.0
```

## License

MIT
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions chromium_build/.gclient
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
solutions = [
{
"name": "src",
"url": "https://chromium.googlesource.com/chromium/src.git",
"managed": False,
"custom_deps": {},
"custom_vars": {
"checkout_pgo_profiles": True,
},
},
]
38 changes: 38 additions & 0 deletions chromium_build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Start from Amazon Linux base image
FROM amazonlinux:2023

ARG CHROMIUM_SHA

# Set environment variables
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV PATH "$PATH:/srv/source/depot_tools"
ENV CHROMIUM_SHA=${CHROMIUM_SHA}

# Update the system and install packages
RUN yum update -y && \
yum groupinstall -y "Development Tools" && \
yum install -y alsa-lib-devel atk-devel bc bluez-libs-devel bzip2-devel cairo-devel cmake cups-devel \
dbus-devel dbus-glib-devel dbus-x11 expat-devel glibc glibc-langpack-en gperf gtk3-devel \
httpd java-17-amazon-corretto libatomic libcap-devel libjpeg-devel libstdc++ libXScrnSaver-devel \
libxkbcommon-x11-devel mod_ssl ncurses-compat-libs nspr-devel nss-devel pam-devel \
pciutils-devel perl php php-cli pulseaudio-libs-devel python python-psutil python-setuptools \
ruby xorg-x11-server-Xvfb zlib \
python3 python3-pip

# Create Directory Structure
RUN mkdir -p /srv/build/chromium /srv/source/chromium

# Clone Depot Tools
RUN git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git /srv/source/depot_tools
ENV PATH "$PATH:/srv/source/depot_tools"

# Copy .gclient file
COPY .gclient /srv/source/chromium/.gclient
# Copy the args; these will have to be moved into the correct place by the chromium builder
COPY args.gn /srv/source/chromium/args.gn

COPY entrypoint.sh /entrypoint.sh
COPY bundle_dependencies.sh /bundle_dependencies.sh

ENTRYPOINT [ "/entrypoint.sh" ]
19 changes: 19 additions & 0 deletions chromium_build/args.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
blink_symbol_level = 0
dcheck_always_on = false
disable_histogram_support = false
enable_basic_print_dialog = false
enable_basic_printing = true
enable_keystone_registration_framework = false
enable_linux_installer = false
enable_media_remoting = true
ffmpeg_branding = "Chrome"
is_component_build = false
is_debug = false
is_official_build = true
proprietary_codecs = true
symbol_level = 0
target_cpu = "x64"
target_os = "linux"
use_sysroot = true
v8_symbol_level = 0
v8_target_cpu = "x64"
28 changes: 28 additions & 0 deletions chromium_build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash -e

# Function to fetch Git SHA from Chromium Revision
get_git_sha_from_revision() {
local revision="$1"
local url="https://cr-rev.appspot.com/_ah/api/crrev/v1/redirect/${revision}"
# Using curl to make an HTTP GET request and extract git_sha from the JSON response
local git_sha=$(curl -s "${url}" | jq -r '.git_sha')
echo "${git_sha}"
}

if [ -z "$1" ]; then
echo "Usage: $0 <Chromium Revision>"
exit 1
fi

chromium_revision="$1"

# Fetching the Git SHA corresponding to the Chromium Revision
git_sha=$(get_git_sha_from_revision "${chromium_revision}")

if [ -z "${git_sha}" ]; then
echo "Failed to fetch the Git SHA for Chromium Revision: ${chromium_revision}"
exit 1
fi

# Build the Docker image, passing the Git SHA as a build-arg
docker build --build-arg CHROMIUM_SHA="${git_sha}" -t chromium-builder .
33 changes: 33 additions & 0 deletions chromium_build/bundle_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Check if user has provided an argument
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <path_to_executable>"
exit 1
fi

# Check if the provided path is an executable
if [ ! -x "$1" ]; then
echo "Error: '$1' is not an executable or doesn't exist."
exit 1
fi

# Create a temporary directory to store the actual files
temp_dir=$(mktemp -d)

# Use ldd to list dependencies and resolve symlinks
ldd "$1" | awk '/=>/ { print $1 " " $3 }' | while read -r dep_name dep_path; do
# Resolve the symlink to the actual file
actual_file=$(readlink -f "$dep_path")

# Copy the actual file to the temporary directory, but rename it
cp "$actual_file" "$temp_dir/$dep_name"
done

# Create a tar archive with the original executable and resolved dependencies
tar -czvf dependencies.tar.gz -C "$temp_dir" .

# Clean up the temporary directory
rm -rf "$temp_dir"

echo "Successfully created dependencies.tar.gz with resolved dependencies."
76 changes: 76 additions & 0 deletions chromium_build/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash -e

if [ "$1" = "build" ]; then
# Execute the rest of the Chromium build steps
cd /srv/source/chromium

# Sync the repository
gclient sync --delete_unversioned_trees --revision $CHROMIUM_SHA --with_branch_heads

# Run hooks
gclient runhooks

# Patching Chromium
awk '{
if ($0 ~ /^\s+PLOG\(WARNING\) << "poll";$/) {
match($0, /^(\\s+)/, arr);
leading_space = arr[1];
print leading_space "PLOG(WARNING) << \"poll\"; failed_polls = 0;";
} else {
print $0;
}
}' /srv/source/chromium/src/content/browser/sandbox_ipc_linux.cc > tmp_file && mv tmp_file /srv/source/chromium/src/content/browser/sandbox_ipc_linux.cc

awk 'BEGIN {flag=0} {
if (flag == 0 && $0 ~ /CHECK\(render_process_host->InSameStoragePartition\(/) {
print "//" $0;
flag = 1;
} else if (flag == 1 && $0 ~ /false \/\* can_create \*\/\)\)\);/) {
print "//" $0;
flag = 0;
} else {
if (flag == 1) {
print "//" $0;
} else {
print $0;
}
}
}' /srv/source/chromium/src/content/browser/renderer_host/render_process_host_impl.cc > tmp_file && mv tmp_file /srv/source/chromium/src/content/browser/renderer_host/render_process_host_impl.cc

# All subsequent commands will be executed in the src directory
cd src

# Create the build configuration directory
mkdir -p /srv/source/chromium/src/out/Default

# Mounting the filesystem like this will require privileged execution of the docker container
mount --types tmpfs --options size=100G,nr_inodes=256k,mode=1777 tmpfs /srv/source/chromium/src/out/Default

# Args was copied over to another location by the build stage
mv /srv/source/chromium/args.gn /srv/source/chromium/src/out/Default/args.gn

# Generate the build configuration
gn gen out/Default

# Compile Chromium
autoninja -C out/Default chrome

# Extract version information, strip symbols, and compress Chromium
CHROMIUM_VERSION=$(sed -r 's~[^0-9]+~~g' chrome/VERSION | tr '\n' '.' | sed 's~[.]$~~')

strip -o /srv/build/chromium/chromium-$CHROMIUM_VERSION out/Default/chrome

brotli --best --force /srv/build/chromium/chromium-$CHROMIUM_VERSION

# Archiving OpenGL ES driver
tar --directory /srv/source/chromium/src/out/Default --create --file /srv/build/chromium/swiftshader.tar libEGL.so libGLESv2.so libvk_swiftshader.so libvulkan.so.1 vk_swiftshader_icd.json

# Compressing OpenGL ES driver
brotli --best --force /srv/build/chromium/swiftshader.tar

# Final artifacts
mv /srv/build/chromium/chromium-$CHROMIUM_VERSION.br /srv/build/chromium/chromium.br
echo $CHROMIUM_VERSION > /srv/build/chromium/VERSION
else
exec "$@"
fi
3 changes: 3 additions & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"116.0.0": "1160321"
}