Last active
February 6, 2024 17:17
-
-
Save aleitner/fe4c8668049b07f32ea2b2782f6c0d4a to your computer and use it in GitHub Desktop.
Build cef
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
ARCH=$(uname -m) | |
# 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" | |
# Variable to hold the build flag | |
BUILD_FLAG="" | |
MANUAL_BUILD=false | |
# 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 \ | |
--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/ | |
} | |
# 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/ | |
} | |
# Process command-line arguments | |
for arg in "$@"; do | |
case $arg in | |
--manual-build) | |
MANUAL_BUILD=true | |
shift # Remove --manual-build from processing | |
;; | |
*) | |
# Unknown option | |
;; | |
esac | |
done | |
# Determine the correct build flag based on the architecture. | |
case "${ARCH}" in | |
"x86_64") | |
BUILD_FLAG="--x64-build" | |
;; | |
"aarch64") | |
BUILD_FLAG="--arm64-build" | |
;; | |
*) | |
echo "Unsupported architecture: ${ARCH}. Exiting..." | |
exit 1 | |
;; | |
esac | |
# is_debug: Indicates whether we are performing 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 provided sysroot or locally installed packages. Set to false to use local packages. | |
# symbol_level: Sets the level of debug symbols. 1 is the minimum level. | |
# 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. | |
# use_allocator: Specifies which memory allocator to use. 'none' defers to the system's C library allocator. | |
GN_DEFINES="use_ozone=true | |
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 " | |
# 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