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

Add Dockerfile and patches for building Chromium with rav1d #519

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
61 changes: 61 additions & 0 deletions package/docker/ubuntu-chromium-x86_64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
FROM ubuntu:22.04

WORKDIR /build

RUN \
apt-get update && \
apt-get install --yes apt-utils curl git lsb-release python3 sudo file nasm && \
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

ENV PATH /build/depot_tools:$PATH

RUN \
mkdir chromium && cd chromium && \
fetch --nohooks --no-history chromium

WORKDIR /build/chromium/src

RUN \
build/install-build-deps.sh && \
gclient runhooks

RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly --component rust-src -y

ENV PATH /root/.cargo/bin:$PATH

# Prerequisites for the rav1d crate
RUN \
vpython3 ./tools/crates/run_gnrt.py download --security-critical no --shipped no paste 1.0.14 && \
vpython3 ./tools/crates/run_gnrt.py download --security-critical no --shipped no cc 1.0.83 && \
vpython3 ./tools/crates/run_gnrt.py download --security-critical no --shipped no heck 0.4.1 && \
vpython3 ./tools/crates/run_gnrt.py download --security-critical no --shipped no num_cpus 1.16.0 && \
vpython3 ./tools/crates/run_gnrt.py download --security-critical no --shipped no bitflags 2.4.0 && \
vpython3 ./tools/crates/run_gnrt.py download --security-critical no --shipped no raw-cpuid 11.0.1 && \
vpython3 ./tools/crates/run_gnrt.py download --security-critical no --shipped no strum_macros 0.25.2 && \
vpython3 ./tools/crates/run_gnrt.py download --security-critical no --shipped no strum 0.25.0 && \
vpython3 ./tools/crates/run_gnrt.py download --security-critical no --shipped no nasm-rs 0.2.5 && \
vpython3 ./tools/crates/run_gnrt.py download --security-critical yes --shipped no rav1d 0.1.0

# Replace the old rav1d pulled from crates.io with ours
RUN \
git clone https://github.com/memorysafety/rav1d/ /build/rav1d && \
rm -rf third_party/rust/rav1d/v0_1 && \
mkdir -p third_party/rust/rav1d/v1/crate && \
cp -r /build/rav1d/* /build/chromium/src/third_party/rust/rav1d/v1/crate/

ADD ./patches /build/patches

# Patches to make everything build
RUN \
git apply /build/patches/add-crate-fix-version.patch && \
git apply /build/patches/swap-deps.patch && \
vpython3 tools/crates/run_gnrt.py gen && \
git apply /build/patches/fix-rustversion.patch && \
git apply /build/patches/add-version-h.patch && \
cp third_party/dav1d/dav1d_generated.gni third_party/rust/rav1d/v1/rav1d_generated.gni && \
sed -i 's/"libdav1d/"crate/g' third_party/rust/rav1d/v1/rav1d_generated.gni && \
cp third_party/dav1d/config/linux/x64/config.asm third_party/rust/rav1d/v1/crate/src/x86/config.asm && \
git apply /build/patches/build-asm.patch && \
gn gen out/Default --args="is_debug = false"

RUN autoninja -C out/Default chrome
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git a/third_party/rust/rav1d/v1/crate/Cargo.toml b/third_party/rust/rav1d/v1/crate/Cargo.toml
--- a/third_party/rust/rav1d/v1/crate/Cargo.toml
+++ b/third_party/rust/rav1d/v1/crate/Cargo.toml
@@ -1,7 +1,7 @@
[workspace]
members = []
[package]
-name = "c2rust_out"
+name = "rav1d"
authors = ["C2Rust"]
-version = "0.0.0"
+version = "1.0.0"
publish = false
Comment on lines +1 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part we can just modify in rav1d directly, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we probably should.


diff --git a/third_party/rust/third_party.toml b/third_party/rust/third_party.toml
--- a/third_party/rust/third_party.toml
+++ b/third_party/rust/third_party.toml
@@ -52,7 +52,8 @@
memoffset = { version = "0.6", features = [ "unstable_const" ] }
proc-macro2 = "1"
qr_code = "2"
quote = "1"
+rav1d = "1"
serde = "1"
static_assertions = "1"
syn = {version = "1", features = ["full"]}
--
66 changes: 66 additions & 0 deletions package/docker/ubuntu-chromium-x86_64/patches/add-version-h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
diff --git a/third_party/rust/rav1d/v1/BUILD.gn b/third_party/rust/rav1d/v1/BUILD.gn
--- a/third_party/rust/rav1d/v1/BUILD.gn
+++ b/third_party/rust/rav1d/v1/BUILD.gn
@@ -119,6 +119,7 @@ cargo_crate("dav1d") {
"//third_party/rust/rav1d/v1/crate/include/dav1d/dav1d.h",
"//third_party/rust/rav1d/v1/crate/include/dav1d/headers.h",
"//third_party/rust/rav1d/v1/crate/include/dav1d/picture.h",
+ "//third_party/rust/rav1d/v1/crate/include/dav1d/version.h",
"//third_party/rust/rav1d/v1/crate/retranspile.md",
"//third_party/rust/rav1d/v1/crate/src/arm/asm-offsets.h",
"//third_party/rust/rav1d/v1/crate/src/arm/cdef.h",
@@ -342,6 +343,7 @@ cargo_crate("seek_stress") {
"//third_party/rust/rav1d/v1/crate/include/dav1d/dav1d.h",
"//third_party/rust/rav1d/v1/crate/include/dav1d/headers.h",
"//third_party/rust/rav1d/v1/crate/include/dav1d/picture.h",
+ "//third_party/rust/rav1d/v1/crate/include/dav1d/version.h",
"//third_party/rust/rav1d/v1/crate/retranspile.md",
"//third_party/rust/rav1d/v1/crate/src/arm/asm-offsets.h",
"//third_party/rust/rav1d/v1/crate/src/arm/cdef.h",
@@ -567,6 +569,7 @@ cargo_crate("lib") {
"//third_party/rust/rav1d/v1/crate/include/dav1d/dav1d.h",
"//third_party/rust/rav1d/v1/crate/include/dav1d/headers.h",
"//third_party/rust/rav1d/v1/crate/include/dav1d/picture.h",
+ "//third_party/rust/rav1d/v1/crate/include/dav1d/version.h",
"//third_party/rust/rav1d/v1/crate/retranspile.md",
"//third_party/rust/rav1d/v1/crate/src/arm/asm-offsets.h",
"//third_party/rust/rav1d/v1/crate/src/arm/cdef.h",
diff --git a/third_party/rust/rav1d/v1/crate/include/dav1d/version.h b/third_party/rust/rav1d/v1/crate/include/dav1d/version.h
new file mode 100644
--- /dev/null
+++ b/third_party/rust/rav1d/v1/crate/include/dav1d/version.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright © 2019, VideoLAN and dav1d authors
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DAV1D_VERSION_H
+#define DAV1D_VERSION_H
+
+#define DAV1D_API_VERSION_MAJOR 6
+#define DAV1D_API_VERSION_MINOR 8
+#define DAV1D_API_VERSION_PATCH 0
+
+#endif /* DAV1D_VERSION_H */
44 changes: 44 additions & 0 deletions package/docker/ubuntu-chromium-x86_64/patches/build-asm.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
diff --git a/third_party/rust/rav1d/v1/BUILD.gn b/third_party/rust/rav1d/v1/BUILD.gn
--- a/third_party/rust/rav1d/v1/BUILD.gn
+++ b/third_party/rust/rav1d/v1/BUILD.gn
@@ -5,7 +5,9 @@
# @generated from third_party/rust/BUILD.gn.hbs by tools/crates/gnrt.
# Do not edit!

+import("rav1d_generated.gni")
import("//build/rust/cargo_crate.gni")
+import("//third_party/nasm/nasm_assemble.gni")

cargo_crate("dav1d") {
crate_type = "bin"
@@ -660,6 +662,7 @@ cargo_crate("lib") {
executable_configs -= [ "//build/config/compiler:chromium_code" ]
executable_configs += [ "//build/config/compiler:no_chromium_code" ]
deps = [
+ ":rav1d_asm",
"//third_party/rust/bitflags/v2:lib",
"//third_party/rust/cfg_if/v1:lib",
"//third_party/rust/libc/v0_2:lib",
@@ -680,3 +683,22 @@ cargo_crate("lib") {
build_root = "crate/build.rs"
build_sources = [ "crate/build.rs" ]
}
+
+nasm_assemble("rav1d_asm") {
+ sources = x86_asm_sources
+
+ inputs = [
+ "crate/src/ext/x86/x86inc.asm",
+ "crate/src/x86/config.asm",
+ ]
+
+ include_dirs = [
+ "crate/src/",
+ "crate/src/x86/"
+ ]
+
+ nasm_flags = [
+ "-P",
+ rebase_path("crate/src/x86/config.asm", root_build_dir),
+ ]
+}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/third_party/rust/rustversion/v1/BUILD.gn b/third_party/rust/rustversion/v1/BUILD.gn
--- a/third_party/rust/rustversion/v1/BUILD.gn
+++ b/third_party/rust/rustversion/v1/BUILD.gn
@@ -57,6 +57,6 @@ cargo_crate("lib") {
executable_configs -= [ "//build/config/compiler:chromium_code" ]
executable_configs += [ "//build/config/compiler:no_chromium_code" ]
build_root = "crate/build/build.rs"
- build_sources = [ "crate/build/build.rs" ]
+ build_sources = [ "crate/build/build.rs", "crate/build/rustc.rs" ]
build_script_outputs = [ "version.rs" ]
}
--
51 changes: 51 additions & 0 deletions package/docker/ubuntu-chromium-x86_64/patches/swap-deps.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
diff --git a/media/filters/BUILD.gn b/media/filters/BUILD.gn
--- a/media/filters/BUILD.gn
+++ b/media/filters/BUILD.gn
@@ -151,7 +151,7 @@ source_set("filters") {
"dav1d_video_decoder.cc",
"dav1d_video_decoder.h",
]
- deps += [ "//third_party/dav1d" ]
+ deps += [ "//third_party/rust/rav1d/v1:lib" ]
}

if (media_use_ffmpeg) {
diff --git a/third_party/libavif/BUILD.gn b/third_party/libavif/BUILD.gn
--- a/third_party/libavif/BUILD.gn
+++ b/third_party/libavif/BUILD.gn
@@ -46,6 +46,6 @@ component("libavif") {
sources += [ "src/src/codec_dav1d.c" ]
include_dirs += [ "../dav1d/libdav1d/include/" ]
defines += [ "AVIF_CODEC_DAV1D" ]
- deps += [ "//third_party/dav1d" ]
+ deps += [ "//third_party/rust/rav1d/v1:lib" ]
}
}

diff --git a/media/filters/dav1d_video_decoder.cc b/media/filters/dav1d_video_decoder.cc
index 02ba3c0a3a..24d93d85ef 100644
--- a/media/filters/dav1d_video_decoder.cc
+++ b/media/filters/dav1d_video_decoder.cc
@@ -23,7 +23,7 @@
#include "media/base/video_util.h"

extern "C" {
-#include "third_party/dav1d/libdav1d/include/dav1d/dav1d.h"
+#include "third_party/rust/rav1d/v1/crate/include/dav1d/dav1d.h"
}

namespace media {
diff --git a/third_party/libavif/BUILD.gn b/third_party/libavif/BUILD.gn
index 3484775ca4..7272e655b3 100644
--- a/third_party/libavif/BUILD.gn
+++ b/third_party/libavif/BUILD.gn
@@ -44,7 +44,7 @@ component("libavif") {

if (enable_dav1d_decoder) {
sources += [ "src/src/codec_dav1d.c" ]
- include_dirs += [ "../dav1d/libdav1d/include/" ]
+ include_dirs += [ "../rust/rav1d/v1/crate/include" ]
defines += [ "AVIF_CODEC_DAV1D" ]
deps += [ "//third_party/rust/rav1d/v1:lib" ]
}