Skip to content

Commit

Permalink
docs(readme): fix build instructions (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
fathyb authored Jan 29, 2023
1 parent eef3322 commit cd84b0d
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ node_modules/
/build
/chromium/*
!/chromium/.gclient
!/chromium/depot_tools
/Cargo.lock
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "libsixel"]
path = libsixel
url = https://github.com/saitoha/libsixel
[submodule "chromium/depot_tools"]
path = chromium/depot_tools
url = https://chromium.googlesource.com/chromium/tools/depot_tools.git
10 changes: 2 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ RUN groupadd -r carbonyl && useradd -r -g carbonyl carbonyl && \
USER carbonyl

ARG TARGETARCH
COPY build/browser/${TARGETARCH:-amd64} /carbonyl
COPY . /carbonyl

ENTRYPOINT [
"/carbonyl/carbonyl",
#
"--no-sandbox",
# Docker's /dev/shm is limited to 64 MB
"--disable-dev-shm-usage"
]
ENTRYPOINT ["/carbonyl/carbonyl", "--no-sandbox", "--disable-dev-shm-usage"]
1 change: 1 addition & 0 deletions chromium/depot_tools
Submodule depot_tools added at b7d8ef
83 changes: 74 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,94 @@ $ docker run -ti fathyb/carbonyl https://youtube.com

## Know issues

- Fullscreen mode not supported yet
- Fullscreen mode not supported yet

## Development

Few notes:

- You need to build Chromium
- Building Carbonyl is almost the same as building Chromium with extra steps to patch and bundle the Rust library. Scripts in the `scripts/` directory are simple wrappers around `gn`, `ninja`, etc..
- Building Chromium for arm64 on Linux requires an amd64 processor
- Carbonyl is only tested on Linux and macOS, other platforms likely require code changes to Chromium
- Chromium is huge and takes a long time to build, making your computer mostly unresponsive. An 8-core CPU such as an M1 Max or an i9 9900k with 10 Gbps fiber takes around ~1 hour to fetch and build. It requires around 100 GB of disk space.

### Fetch

> Fetch Chromium's code.
```console
$ cd chromium
$ gclient sync
$ ./scripts/gclient.sh sync
```

### Apply patches

> Any changes made to Chromium will be reverted, make sure to save any changes you made.
```console
$ ./scripts/patches.sh apply
```

### Configure

> You need to disable `lld` on macOS because of a linking bug related to Rust and `compact_unwind`
```console
$ ./scripts/gn.sh args out/Default
```

> `Default` is the target name, you can use multiple ones and pick any name you'd like, i.e.:
>
> ```console
> $ ./scripts/gn.sh args out/release
> $ ./scripts/gn.sh args out/debug
> # or if you'd like to build a multi-platform image
> $ ./scripts/gn.sh args out/arm64
> $ ./scripts/gn.sh args out/amd64
> ```
When prompted, enter the following arguments:
```gn
import("//carbonyl/src/browser/args.gn")
# uncomment this to build for arm64
# target_cpu="arm64"
# uncomment this to enable ccache
# cc_wrapper="env CCACHE_SLOPPINESS=time_macros ccache"
# uncomment this if you're building for macOS
# use_lld=false
# uncomment this for a release build
# is_debug=false
# symbol_level=0
```
### Build binaries

```console
$ cd chromium/src
$ gn gen out/Default
$ ./scripts/build.sh Default
```

### Build
This should produce the following outputs:

- `out/Default/headless_shell`: browser binary
- `out/Default/icudtl.dat`
- `out/Default/libEGL.so`
- `out/Default/libGLESv2.so`
- `out/Default/v8_context_snapshot.bin`

### Build Docker image

```console
$ cd chromium/src
$ ninja -C out/Default headless:headless_shell
# Build arm64 Docker image using binaries from the Default target
$ ./scripts/docker.sh arm64 Default
# Build amd64 Docker image using binaries from the Default target
$ ./scripts/docker.sh amd64 Default
```

### Run

```
$ ./scripts/run.sh Default https://wikipedia.org
```
34 changes: 28 additions & 6 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
#!/usr/bin/env bash

set -eo pipefail
export CARBONYL_ROOT=$(cd $(dirname -- "$0") && dirname -- $(pwd))

target="$1"
source "$CARBONYL_ROOT/scripts/env.sh"

shift
platform="linux"
cpu=$(uname -m)

scripts/ninja.sh "$target"
electron/src/electron/script/strip-binaries.py -d "electron/src/out/$target" "$@"
ninja -C "electron/src/out/$target" electron:electron_dist_zip
if [[ "$cpu" == "arm64" ]]; then
cpu="aarch64"
fi

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
platform="unknown-linux-gnu"
elif [[ "$OSTYPE" == "darwin"* ]]; then
platform="apple-darwin"
else
echo "Unsupported platform: $OSTYPE"

exit 2
fi

target="$cpu-$platform"

if grep -q "is_debug\s*=\s*false" "$CHROMIUM_SRC/out/$1/args.gn"; then
cargo build --target "$target" --release
else
cargo build --target "$target"
fi

cd "$CHROMIUM_SRC/out/$1"

ninja headless:headless_shell
8 changes: 0 additions & 8 deletions scripts/docker-entrypoint.sh

This file was deleted.

33 changes: 33 additions & 0 deletions scripts/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

export CARBONYL_ROOT=$(cd $(dirname -- "$0") && dirname -- $(pwd))

source "$CARBONYL_ROOT/scripts/env.sh"

cpu="$1"
target="$2"

build_dir="$CARBONYL_ROOT/build/browser/$cpu"

rm -rf "$build_dir"
mkdir -p "$build_dir"
cd "$build_dir"

cp "$CARBONYL_ROOT/Dockerfile" .
cp "$CHROMIUM_SRC/out/$target/headless_shell" carbonyl
cp "$CHROMIUM_SRC/out/$target/icudtl.dat" .
cp "$CHROMIUM_SRC/out/$target/libEGL.so" .
cp "$CHROMIUM_SRC/out/$target/libGLESv2.so" .
cp "$CHROMIUM_SRC/out/$target/v8_context_snapshot.bin" .

if [[ "$cpu" == "arm64" ]]; then
aarch64-linux-gnu-strip carbonyl *.so
else
strip carbonyl *.so
fi

tag="fathyb/carbonyl:$cpu"

docker buildx build . --load --platform "linux/$cpu" --tag "$tag"

echo "Image tag: $tag"
14 changes: 14 additions & 0 deletions scripts/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -eo pipefail

export CHROMIUM_ROOT="$CARBONYL_ROOT/chromium"
export CHROMIUM_SRC="$CHROMIUM_ROOT/src"
export DEPOT_TOOLS_ROOT="$CHROMIUM_ROOT/depot_tools"
export PATH="$PATH:$DEPOT_TOOLS_ROOT"

if [ ! -d "$DEPOT_TOOLS_ROOT" ]; then
echo "depot_tools not found, fetching submodule.."

git -C "$CARBONYL_ROOT" submodule update --init --recursive
fi
9 changes: 6 additions & 3 deletions scripts/gclient.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash

set -exo pipefail
export CARBONYL_ROOT=$(cd $(dirname -- "$0") && dirname -- $(pwd))

cd electron
source "$CARBONYL_ROOT/scripts/env.sh"

gclient sync --with_tags "$@"
(
cd "$CHROMIUM_ROOT" &&
gclient "$@"
)
12 changes: 6 additions & 6 deletions scripts/gn.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bash

set -eo pipefail
export CARBONYL_ROOT=$(cd $(dirname -- "$0") && dirname -- $(pwd))

mode="$1"
shift
source "$CARBONYL_ROOT/scripts/env.sh"

cd electron/src
CHROMIUM_BUILDTOOLS_PATH=`pwd`/buildtools \
gn gen "out/${mode}" --args="import(\"//electron/build/args/$mode.gn\") ${GN_ARGS}" "$@"
(
cd "$CHROMIUM_SRC" &&
gn "$@"
)
8 changes: 0 additions & 8 deletions scripts/ninja.sh

This file was deleted.

6 changes: 0 additions & 6 deletions scripts/patch.sh

This file was deleted.

42 changes: 42 additions & 0 deletions scripts/patches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

export CARBONYL_ROOT=$(cd $(dirname -- "$0") && dirname -- $(pwd))

source "$CARBONYL_ROOT/scripts/env.sh"

cd "$CHROMIUM_SRC"

chromium_upstream="111.0.5511.1"
skia_upstream="486deb23bc2a4d3d09c66fef52c2ad64d8b4f761"

if [[ "$1" == "apply" ]]; then
echo "Stashing Chromium changes.."
git add -A carbonyl
git stash
git checkout "$chromium_upstream"
echo "Applying Chromium patches.."
git apply < ../../src/chromium.patch

cd third_party/skia
echo "Stashing Chromium changes.."
git stash
git checkout "$skia_upstream"
echo "Applying Skia patches.."
git apply < ../../../../src/skia.patch

echo "Patches successfully applied"
elif [[ "$1" == "save" ]]; then
echo "Updating Chromium patch.."
git add -A carbonyl
git diff "$chromium_upstream" > ../../src/chromium.patch

echo "Updating Skia patch.."
cd third_party/skia
git diff "$skia_upstream" > ../../../../src/skia.patch

echo "Patches successfully updated"
else
echo "Unknown argument: $1"

exit 2
fi
10 changes: 10 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

export CARBONYL_ROOT=$(cd $(dirname -- "$0") && dirname -- $(pwd))

source "$CARBONYL_ROOT/scripts/env.sh"

target="$1"
shift

"$CHROMIUM_SRC/out/$target/headless_shell" "$@"
17 changes: 17 additions & 0 deletions src/browser/args.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
enable_nacl=false
headless_enable_commands=false
headless_use_embedded_resources=true
enable_pdf=false
enable_printing=false
enable_ppapi=false
enable_plugins=false
enable_browser_speech_service=false
enable_component_updater=false
enable_media_remoting=false
enable_print_preview=false
enable_rust_json=false
enable_screen_ai_service=false
enable_speech_service=false
enable_system_notifications=false
enable_tagged_pdf=false
enable_webui_certificate_viewer=false

0 comments on commit cd84b0d

Please sign in to comment.