Skip to content

Instantly share code, notes, and snippets.

@aleitner
Last active February 6, 2024 17:17
Show Gist options
  • Save aleitner/fe4c8668049b07f32ea2b2782f6c0d4a to your computer and use it in GitHub Desktop.
Save aleitner/fe4c8668049b07f32ea2b2782f6c0d4a to your computer and use it in GitHub Desktop.
Build cef
#!/usr/bin/env bash
set -e
# Define the build directory and ensure it exists.
BUILD_DIR="${HOME}/code"
AUTOMATE_DIR="${BUILD_DIR}/automate"
CHROMIUM_DIR="${BUILD_DIR}/chromium_git"
CEF_DIR="${CHROMIUM_DIR}/chromium/src/cef"
# Ensure the build and automate directories exist.
mkdir -p ${BUILD_DIR}
mkdir -p ${AUTOMATE_DIR}
# Define the release branch number.
RELEASE_BRANCH="6045"
# Determine the correct build flag based on the architecture.
ARCH=$(uname -m)
BUILD_FLAG=""
case "${ARCH}" in
"x86_64")
BUILD_FLAG="--x64-build"
;;
"aarch64")
BUILD_FLAG="--arm64-build"
;;
*)
echo "Unsupported architecture: ${ARCH}. Exiting..."
exit 1
;;
esac
# Process command-line arguments
MANUAL_BUILD=false
for arg in "$@"; do
case $arg in
--manual-build)
MANUAL_BUILD=true
shift # Remove --manual-build from processing
;;
*)
# Unknown option
;;
esac
done
# Function to run the build command
run_build() {
echo "Running the automate build script..."
python3 "${AUTOMATE_SCRIPT}" \
--download-dir="${CHROMIUM_DIR}" \
--branch="${RELEASE_BRANCH}" \
--minimal-distrib \
--force-clean \
--force-clean-deps \
--no-debug-build \
--no-distrib-docs \
--no-distrib-archive \
--build-target="cefclient chrome_sandbox"\
--distrib-subdir=libcef \
${BUILD_FLAG}
rm -rf /opt/cef
mkdir -p /opt/cef
cp -r ${CHROMIUM_DIR}/chromium/src/cef/binary_distrib/libcef/* /opt/cef/
cd /opt/cef
for file in Resources/*; do ln -s "../$file" Release/; done
}
# Function to run the script to build manually
run_manual_build() {
echo "Running the automate script without building..."
python3 "${AUTOMATE_SCRIPT}" \
--download-dir="${CHROMIUM_DIR}" \
--branch="${RELEASE_BRANCH}" \
--no-distrib \
--no-build \
--force-clean \
--force-clean-deps
# Update PATH
export PATH="${CHROMIUM_DIR}/depot_tools:$PATH"
# Navigate to the CEF directory and create CEF projects
cd "${CEF_DIR}"
./cef_create_projects.sh
# Navigate to the src directory and build cefsimple
cd "${CHROMIUM_DIR}/chromium/src"
autoninja -C out/Release_GN_x64 cefsimple chrome_sandbox
# Create a CEF binary distribution
cd "${CEF_DIR}/tools"
./make_distrib.sh --ninja-build --no-symbols --no-docs --no-archive --minimal --distrib-subdir=libcef ${BUILD_FLAG}
# Copy distribution to /opt/cef
rm -rf /opt/cef
mkdir -p /opt/cef
cp -r ${CHROMIUM_DIR}/chromium/src/cef/binary_distrib/libcef_minimal/* /opt/cef/
cd /opt/cef
for file in Resources/*; do ln -s "../$file" Release/; done
}
# is_debug: Indicates whether to perform a debug build. Set to false for a release build.
# chrome_pgo_phase: Controls Profile-Guided Optimization. Set to 0 to disable.
# use_sysroot: Determines whether the build uses the Chromium-provided sysroot or locally installed packages. Usually set to true to use Chromium's sysroot.
# symbol_level: Sets the level of debug symbols. 1 is the minimum level for backtrace symbols.
# is_cfi: Enables or disables Control Flow Integrity checks. Set to false to disable.
# use_thin_lto: Enables or disables Thin Link Time Optimization. Set to false to disable.
# use_vaapi: Determines whether to use the Video Acceleration API. Set to false to disable when building for headless environments.
# use_allocator: Specifies which memory allocator to use. 'none' defers to the system's C library allocator.
# ozone_platform_headless: Enables the headless Ozone platform which doesn't require display server dependencies. Set to true for headless builds.
export GN_DEFINES="is_official_build=true \
is_debug=false \
chrome_pgo_phase=0 \
use_sysroot=true \
symbol_level=1 \
is_cfi=false \
use_thin_lto=false \
use_vaapi=false \
use_allocator=none \
use_ozone=true \
ozone_auto_platforms=false \
ozone_platform_headless=true \
ozone_platform_x11=false \
ozone_platform_wayland=false \
ozone_platform_drm=false"
# Detect OS distribution and architecture
OS_ID=""
if command -v lsb_release >/dev/null; then
OS_ID=$(lsb_release -si)
elif [ -f "/etc/os-release" ]; then
OS_ID=$(grep ^ID= /etc/os-release | cut -d'=' -f 2)
else
echo "Unable to detect OS distribution. Exiting..."
exit 1
fi
# Install Ubuntu build dependencies using provided script.
DEPS_SCRIPT="${BUILD_DIR}/install-build-deps.py"
if [[ "$OS_ID" == "Ubuntu" ]] && [ ! -f "${DEPS_SCRIPT}" ]; then
echo "Installing build dependencies..."
curl 'https://chromium.googlesource.com/chromium/src/+/main/build/install-build-deps.py?format=TEXT' | base64 -d > "${DEPS_SCRIPT}"
sudo python3 "${DEPS_SCRIPT}" --no-arm --no-chromeos-fonts --no-nacl
fi
# Common build dependencies with Python packages
sudo python3 -m pip install dataclasses importlib_metadata
# Download the automate-git.py script into the automate directory if it doesn't exist.
AUTOMATE_SCRIPT="${AUTOMATE_DIR}/automate-git.py"
AUTOMATE_SCRIPT_URL="https://bitbucket.org/chromiumembedded/cef/raw/master/tools/automate/automate-git.py"
if [ ! -f "${AUTOMATE_SCRIPT}" ]; then
echo "Downloading the automate-git.py script..."
curl ${AUTOMATE_SCRIPT_URL} -o ${AUTOMATE_SCRIPT}
fi
# Run the appropriate function based on the --no-build option
if [ "$MANUAL_BUILD" = true ]; then
run_manual_build
else
run_build
fi
echo "Build process completed successfully"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment