build chromium
突发奇想,构建 chrome 比较复杂,但 docker 刚好可以解决构建环境的问题,应该比较简单,所以做个尝试。
背景
看到 Hacker News 上的话题 Fixing a bug in Google Chrome as a first-time contributor,感觉还是挺不错的。
且近来看到 gcc 的内容,遂尝试。
Clone 代码
# chromium 源码
$ git clone https://chromium.googlesource.com/chromium/src --depth 1
# depot_tools 源码
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --depth 1
Dockerfile
参考 https://chromium.googlesource.com/chromium/src/+/main/docs/linux/build_instructions.md#Docker
# 视情况开启加速
FROM mirror.gcr.io/ubuntu:22.04
# 视情况开启加速
# 清华镜像 https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
# RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse" > /etc/apt/sources.list
# RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse" >> /etc/apt/sources.list
# RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse" >> /etc/apt/sources.list
# RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse" >> /etc/apt/sources.list
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
# Install Mantatory tools (curl git python3) and optional tools (vim sudo)
RUN apt-get update && \
apt-get install -y curl git lsb-release python3 git file vim sudo && \
rm -rf /var/lib/apt/lists/*
# Export depot_tools path
ENV PATH="/depot_tools:${PATH}"
# Configure git for safe.directory
RUN git config --global --add safe.directory /depot_tools && \
git config --global --add safe.directory /chromium/src
# Set the working directory to the existing Chromium source directory.
# This can be either "/chromium/src" or "/chromium".
WORKDIR /chromium/src
# Expose any necessary ports (if needed)
# EXPOSE 8080
RUN useradd -u 1000 chrom-d
# Create normal user with name "chrom-d". Optional and you can use root but
# not advised.
USER chrom-d
# Start Chromium Builder "chrom-d" (modify this command as needed)
# CMD ["autoninja -C out/Default chrome"]
CMD ["bash"]
构建 Docker
参考 https://chromium.googlesource.com/chromium/src/+/main/docs/linux/build_instructions.md#Docker
# 构建镜像
$ docker build -t chrom-b .
# 启动
$ docker run --rm \
-it \
--name chrom-b \
-u root \
-v /Users/zhoukeke/chrome:/chromium \
-v /Users/zhoukeke/chrome/depot_tools:/depot_tools \
chrom-b
# docker 容器中执行
$ ./build/install-build-deps.sh
# docker 容器中执行
# https://stackoverflow.com/a/35382199/4992897
$ gclient config https://chromium.googlesource.com/chromium/src
# 此步骤太慢了,下载代码有 20G+,中途 docker 崩溃了
$ gclient sync
$ gclient runhooks
保存 docker 实例为新镜像
$ docker ps
# 后续可直接运行
$ docker commit <ps出来的containerid> chrom-b:v1
后续工作
- 需要一台空间更大的电脑
- 最好是原生 ubuntu 系统
- 内存也需要大一些的电脑
- https://chromium.googlesource.com/chromium/src/+/main/docs/linux/build_instructions.md
- 看到指南中,可能存在 LLVM ERROR: out of memory