mirror of
https://github.com/fathyb/carbonyl.git
synced 2024-09-17 13:49:40 +03:00
chore: add ci (#53)
This commit is contained in:
parent
89084ba541
commit
1c548bee6d
96
.refloat/config.js
Normal file
96
.refloat/config.js
Normal file
@ -0,0 +1,96 @@
|
||||
const sharedLib = {
|
||||
macos: 'dylib',
|
||||
linux: 'so'
|
||||
}
|
||||
const platforms = {
|
||||
macos: 'apple-darwin',
|
||||
linux: 'unknown-linux-gnu',
|
||||
}
|
||||
const archs = {
|
||||
arm64: 'aarch64',
|
||||
amd64: 'x86_64',
|
||||
}
|
||||
|
||||
export const jobs = ['arm64', 'amd64']
|
||||
.flatMap((arch) =>
|
||||
['macos', 'linux'].map((platform) => ({ platform, arch })),
|
||||
)
|
||||
.map(({ platform, arch }) => {
|
||||
const triple = `${archs[arch]}-${platforms[platform]}`
|
||||
const lib = `build/${triple}/release/libcarbonyl.${sharedLib[platform]}`
|
||||
|
||||
return { platform, arch, triple, lib }
|
||||
})
|
||||
.flatMap(({ platform, arch, triple, lib }) => [
|
||||
{
|
||||
name: `Build core (${platform}/${arch})`,
|
||||
docker:
|
||||
platform === 'linux'
|
||||
? {
|
||||
image: 'fathyb/rust-cross',
|
||||
cache: ['/usr/local/cargo/registry'],
|
||||
}
|
||||
: undefined,
|
||||
agent: { tags: platform === 'linux' ? ['docker'] : ['macos'] },
|
||||
steps: [
|
||||
{
|
||||
name: 'Install Rust toolchain',
|
||||
command: `rustup target add ${triple}`,
|
||||
},
|
||||
{
|
||||
name: 'Build core library',
|
||||
command: `cargo build --target ${triple} --release`,
|
||||
env: { MACOSX_DEPLOYMENT_TARGET: '10.13' },
|
||||
},
|
||||
{
|
||||
name: 'Set core library install name',
|
||||
command:
|
||||
platform === 'macos'
|
||||
? `install_name_tool -id @executable_path/libcarbonyl.dylib ${lib}`
|
||||
: 'echo not necessary',
|
||||
},
|
||||
{
|
||||
export: {
|
||||
workspace: triple,
|
||||
path: 'build/*/release/*.{dylib,so,dll}',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
// TODO: setup shared build dir
|
||||
name: `Build (${platform}/${arch})`,
|
||||
docker: 'fathyb/rust-cross',
|
||||
agent: { tags: ['docker'] },
|
||||
steps: [
|
||||
{
|
||||
import: {
|
||||
workspace: triple,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Fetch binaries',
|
||||
command: `scripts/runtime-pull.sh ${triple}`,
|
||||
},
|
||||
{
|
||||
name: 'Zip binaries',
|
||||
command: `
|
||||
mkdir build/zip
|
||||
cp -r build/pre-built/${triple} build/zip/${triple}
|
||||
cp ${lib} build/zip/${triple}
|
||||
|
||||
cd build/zip/${triple}
|
||||
zip -r package.zip .
|
||||
`,
|
||||
},
|
||||
{
|
||||
export: {
|
||||
artifact: {
|
||||
name: `carbonyl.${platform}-${arch}.zip`,
|
||||
path: `build/zip/${triple}/package.zip`,
|
||||
},
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
])
|
@ -12,4 +12,4 @@ chrono = "0.4.23"
|
||||
[lib]
|
||||
name = "carbonyl"
|
||||
path = "src/lib.rs"
|
||||
crate-type = ["staticlib"]
|
||||
crate-type = ["cdylib"]
|
||||
|
19
Dockerfile
19
Dockerfile
@ -1,3 +1,22 @@
|
||||
FROM rust:1.67 AS cross-compile
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y \
|
||||
zip g++-aarch64-linux-gnu g++-x86-64-linux-gnu libc6-dev-arm64-cross libc6-dev-amd64-cross && \
|
||||
rustup target add aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu && \
|
||||
rustup toolchain install stable-aarch64-unknown-linux-gnu stable-x86_64-unknown-linux-gnu && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ENV AR_AARCH64_UNKNOWN_LINUX_GNU=aarch64-linux-gnu-ar
|
||||
ENV CC_AARCH64_UNKNOWN_LINUX_GNU=aarch64-linux-gnu-gcc
|
||||
ENV CXX_AARCH64_UNKNOWN_LINUX_GNU=aarch64-linux-gnu-g++
|
||||
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
|
||||
|
||||
ENV AR_X86_64_UNKNOWN_LINUX_GNU=x86_64-linux-gnu-ar
|
||||
ENV CC_X86_64_UNKNOWN_LINUX_GNU=x86_64-linux-gnu-gcc
|
||||
ENV CXX_X86_64_UNKNOWN_LINUX_GNU=x86_64-linux-gnu-g++
|
||||
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc
|
||||
|
||||
FROM debian:bullseye-slim
|
||||
|
||||
RUN groupadd -r carbonyl && useradd -r -g carbonyl carbonyl && \
|
||||
|
@ -2,36 +2,20 @@
|
||||
|
||||
export CARBONYL_ROOT=$(cd $(dirname -- "$0") && dirname -- "$(pwd)")
|
||||
|
||||
source "$CARBONYL_ROOT/scripts/env.sh"
|
||||
cd $CARBONYL_ROOT
|
||||
source scripts/env.sh
|
||||
|
||||
target="$1"
|
||||
cpu="$2"
|
||||
platform="linux"
|
||||
triple=$(scripts/platform-triple.sh "$2")
|
||||
|
||||
if [ -z "$cpu" ]; then
|
||||
cpu="$(uname -m)"
|
||||
export MACOSX_DEPLOYMENT_TARGET=10.13
|
||||
cargo build --target "$triple" --release
|
||||
|
||||
if [ -f "build/$triple/release/libcarbonyl.dylib" ]; then
|
||||
install_name_tool \
|
||||
-id @executable_path/libcarbonyl.dylib \
|
||||
"build/$triple/release/libcarbonyl.dylib"
|
||||
fi
|
||||
|
||||
if [[ "$cpu" == "arm64" ]]; then
|
||||
cpu="aarch64"
|
||||
elif [[ "$cpu" == "amd64" ]]; then
|
||||
cpu="x86_64"
|
||||
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"
|
||||
|
||||
cargo build --target "$target" --release
|
||||
|
||||
cd "$CHROMIUM_SRC/out/$1"
|
||||
|
||||
ninja headless:headless_shell
|
||||
|
31
scripts/copy-binaries.sh
Executable file
31
scripts/copy-binaries.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export CARBONYL_ROOT=$(cd $(dirname -- "$0") && dirname -- $(pwd))
|
||||
|
||||
cd "$CARBONYL_ROOT"
|
||||
source "scripts/env.sh"
|
||||
|
||||
target="$1"
|
||||
cpu="$2"
|
||||
|
||||
triple=$(scripts/platform-triple.sh "$cpu")
|
||||
dest="build/pre-built/$triple"
|
||||
src="chromium/src/out/$target"
|
||||
|
||||
lib_ext="so"
|
||||
if [ -f "$src"/libEGL.dylib ]; then
|
||||
lib_ext="dylib"
|
||||
fi
|
||||
|
||||
rm -rf "$dest"
|
||||
mkdir -p "$dest"
|
||||
|
||||
cp "$src/headless_shell" "$dest/carbonyl"
|
||||
cp "$src/icudtl.dat" "$dest"
|
||||
cp "$src/libEGL.$lib_ext" "$dest"
|
||||
cp "$src/libGLESv2.$lib_ext" "$dest"
|
||||
cp "$src"/v8_context_snapshot*.bin "$dest"
|
||||
cp "build/$triple/release/libcarbonyl.$lib_ext" "$dest"
|
||||
|
||||
echo "Binaries copied to $dest"
|
||||
|
11
scripts/env.sh
Normal file → Executable file
11
scripts/env.sh
Normal file → Executable file
@ -2,12 +2,17 @@
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
export CHROMIUM_ROOT="$CARBONYL_ROOT/chromium"
|
||||
if [ -z "$CHROMIUM_ROOT" ]; then
|
||||
export CHROMIUM_ROOT="$CARBONYL_ROOT/chromium"
|
||||
fi
|
||||
if [ -z "$DEPOT_TOOLS_ROOT" ]; then
|
||||
export DEPOT_TOOLS_ROOT="$CHROMIUM_ROOT/depot_tools"
|
||||
fi
|
||||
|
||||
export CHROMIUM_SRC="$CHROMIUM_ROOT/src"
|
||||
export DEPOT_TOOLS_ROOT="$CHROMIUM_ROOT/depot_tools"
|
||||
export PATH="$PATH:$DEPOT_TOOLS_ROOT"
|
||||
|
||||
if [ ! -f "$DEPOT_TOOLS_ROOT/README.md" ]; then
|
||||
if [ ! -f "$DEPOT_TOOLS_ROOT/README.md" ] && [ -z "$SKIP_DEPOT_TOOLS" ]; then
|
||||
echo "depot_tools not found, fetching submodule.."
|
||||
|
||||
git -C "$CARBONYL_ROOT" submodule update --init --recursive
|
||||
|
@ -19,14 +19,14 @@ if [[ "$1" == "apply" ]]; then
|
||||
git stash
|
||||
git checkout "$chromium_upstream"
|
||||
echo "Applying Chromium patches.."
|
||||
git apply < ../../src/chromium.patch
|
||||
git apply < "$CARBONYL_ROOT/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
|
||||
git apply < "$CARBONYL_ROOT/src/skia.patch"
|
||||
|
||||
echo "Patches successfully applied"
|
||||
elif [[ "$1" == "save" ]]; then
|
||||
@ -35,11 +35,11 @@ elif [[ "$1" == "save" ]]; then
|
||||
fi
|
||||
|
||||
echo "Updating Chromium patch.."
|
||||
git diff "$chromium_upstream" > ../../src/chromium.patch
|
||||
git diff "$chromium_upstream" > "$CARBONYL_ROOT/src/chromium.patch"
|
||||
|
||||
echo "Updating Skia patch.."
|
||||
cd third_party/skia
|
||||
git diff "$skia_upstream" > ../../../../src/skia.patch
|
||||
git diff "$skia_upstream" > "$CARBONYL_ROOT/src/skia.patch"
|
||||
|
||||
echo "Patches successfully updated"
|
||||
else
|
||||
|
32
scripts/platform-triple.sh
Executable file
32
scripts/platform-triple.sh
Executable file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export CARBONYL_ROOT=$(cd $(dirname -- "$0") && dirname -- $(pwd))
|
||||
|
||||
source "$CARBONYL_ROOT/scripts/env.sh"
|
||||
|
||||
cpu="$1"
|
||||
platform="$2"
|
||||
|
||||
if [ -z "$platform" ]; then
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
platform="unknown-linux-gnu"
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
platform="apple-darwin"
|
||||
else
|
||||
echo "Unsupported platform: $OSTYPE"
|
||||
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$cpu" ]; then
|
||||
cpu="$(uname -m)"
|
||||
fi
|
||||
|
||||
if [[ "$cpu" == "arm64" ]]; then
|
||||
cpu="aarch64"
|
||||
elif [[ "$cpu" == "amd64" ]]; then
|
||||
cpu="x86_64"
|
||||
fi
|
||||
|
||||
echo -n "$cpu-$platform"
|
16
scripts/runtime-hash.sh
Executable file
16
scripts/runtime-hash.sh
Executable file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export CARBONYL_ROOT=$(cd $(dirname -- "$0") && dirname -- $(pwd))
|
||||
|
||||
cd "$CARBONYL_ROOT"
|
||||
source "scripts/env.sh"
|
||||
|
||||
for file in chromium/.gclient src/*.patch src/browser/*.{cc,h,gn,mojom}; do
|
||||
file_sha=$(cat "$file" | openssl sha256)
|
||||
result=$(echo -n "$sha/${file_sha: -64}" | openssl sha256)
|
||||
sha+="${file_sha: -64} ${file}"$'\n'
|
||||
done
|
||||
|
||||
hash=$(echo "$sha" | sort | openssl sha256)
|
||||
|
||||
echo -n "${hash: -16}"
|
30
scripts/runtime-pull.sh
Executable file
30
scripts/runtime-pull.sh
Executable file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export CARBONYL_ROOT=$(cd $(dirname -- "$0") && dirname -- $(pwd))
|
||||
export SKIP_DEPOT_TOOLS="true"
|
||||
|
||||
cd "$CARBONYL_ROOT"
|
||||
source "scripts/env.sh"
|
||||
|
||||
echo "Computing Chromium patches sha.."
|
||||
|
||||
sha=$(scripts/runtime-hash.sh)
|
||||
|
||||
triple="$1"
|
||||
url="https://carbonyl.fathy.fr/runtime/$sha/$triple.tgz"
|
||||
|
||||
echo "Downloading pre-built binaries from $url"
|
||||
|
||||
mkdir -p build/pre-built
|
||||
|
||||
if ! curl --silent --fail --output "build/pre-built/$triple.tgz" "$url"; then
|
||||
echo "Pre-built binaries not available"
|
||||
|
||||
exit 1
|
||||
else
|
||||
echo "Pre-build binaries available, extracting.."
|
||||
|
||||
cd build/pre-built
|
||||
rm -rf "$triple"
|
||||
tar -xvzf "$triple.tgz"
|
||||
fi
|
29
scripts/runtime-push.sh
Executable file
29
scripts/runtime-push.sh
Executable file
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export CARBONYL_ROOT=$(cd $(dirname -- "$0") && dirname -- $(pwd))
|
||||
|
||||
cd "$CARBONYL_ROOT"
|
||||
source "scripts/env.sh"
|
||||
|
||||
echo "Computing Chromium patches hash.."
|
||||
|
||||
hash=$(scripts/runtime-hash.sh)
|
||||
triple=$(scripts/platform-triple.sh "$1")
|
||||
|
||||
echo "Archiving binaries.."
|
||||
|
||||
cd build/pre-built
|
||||
tar cvzf "$triple.tgz" "$triple"
|
||||
|
||||
echo "Binaries archived to build/pre-built/$triple.tgz"
|
||||
|
||||
echo "Pushing $triple.tgz to object storage.."
|
||||
|
||||
AWS_PAGER="" \
|
||||
AWS_ACCESS_KEY_ID="$CDN_ACCESS_KEY_ID" \
|
||||
AWS_SECRET_ACCESS_KEY="$CDN_SECRET_ACCESS_KEY" \
|
||||
aws s3api put-object \
|
||||
--endpoint-url "https://7985f304d3a79d71fb63aeb17a31fe30.r2.cloudflarestorage.com" \
|
||||
--bucket "carbonyl-runtime" \
|
||||
--key "runtime/$hash/$triple.tgz" \
|
||||
--body "$triple.tgz"
|
@ -37,11 +37,12 @@ component("carbonyl") {
|
||||
target += "aarch64-"
|
||||
}
|
||||
|
||||
if (is_linux) {
|
||||
target += "unknown-linux-gnu"
|
||||
} else if (is_mac) {
|
||||
if (is_mac) {
|
||||
target += "apple-darwin"
|
||||
} else if (is_linux) {
|
||||
target += "unknown-linux-gnu"
|
||||
}
|
||||
|
||||
libs = ["//carbonyl/build/$target/release/libcarbonyl.a"]
|
||||
libs = ["carbonyl"]
|
||||
lib_dirs = ["//carbonyl/build/$target/release"]
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
enable_nacl=false
|
||||
headless_enable_commands=false
|
||||
headless_use_embedded_resources=true
|
||||
|
||||
# Disable unused features
|
||||
enable_nacl=false
|
||||
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
|
||||
|
@ -9,10 +9,6 @@ use crate::gfx::{Cast, Color, Point, Rect, Size};
|
||||
use crate::output::Renderer;
|
||||
use crate::{input, output, utils::log};
|
||||
|
||||
/// This file bridges the C++ code with Rust.
|
||||
/// "C-unwind" combined with .unwrap() is used to allow catching Rust panics
|
||||
/// using C++ exception handling.
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CSize {
|
||||
width: c_uint,
|
||||
@ -115,14 +111,14 @@ fn main() -> io::Result<Option<i32>> {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C-unwind" fn carbonyl_shell_main() {
|
||||
pub extern "C" fn carbonyl_shell_main() {
|
||||
if let Some(code) = main().unwrap() {
|
||||
std::process::exit(code)
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C-unwind" fn carbonyl_renderer_create() -> *mut Renderer {
|
||||
pub extern "C" fn carbonyl_renderer_create() -> *mut Renderer {
|
||||
let mut renderer = Box::new(Renderer::new());
|
||||
let src = output::size().unwrap();
|
||||
|
||||
@ -134,24 +130,21 @@ pub extern "C-unwind" fn carbonyl_renderer_create() -> *mut Renderer {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C-unwind" fn carbonyl_renderer_clear_text(renderer: *mut Renderer) {
|
||||
pub extern "C" fn carbonyl_renderer_clear_text(renderer: *mut Renderer) {
|
||||
let renderer = unsafe { &mut *renderer };
|
||||
|
||||
renderer.clear_text()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C-unwind" fn carbonyl_renderer_set_title(
|
||||
renderer: *mut Renderer,
|
||||
title: *const c_char,
|
||||
) {
|
||||
pub extern "C" fn carbonyl_renderer_set_title(renderer: *mut Renderer, title: *const c_char) {
|
||||
let (renderer, title) = unsafe { (&mut *renderer, CStr::from_ptr(title)) };
|
||||
|
||||
renderer.set_title(title.to_str().unwrap()).unwrap()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C-unwind" fn carbonyl_renderer_draw_text(
|
||||
pub extern "C" fn carbonyl_renderer_draw_text(
|
||||
renderer: *mut Renderer,
|
||||
text: *const c_char,
|
||||
rect: *const CRect,
|
||||
@ -169,7 +162,7 @@ pub extern "C-unwind" fn carbonyl_renderer_draw_text(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C-unwind" fn carbonyl_renderer_draw_background(
|
||||
pub extern "C" fn carbonyl_renderer_draw_background(
|
||||
renderer: *mut Renderer,
|
||||
pixels: *mut c_uchar,
|
||||
pixels_size: size_t,
|
||||
@ -195,7 +188,7 @@ pub extern "C-unwind" fn carbonyl_renderer_draw_background(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C-unwind" fn carbonyl_output_get_size(size: *mut CSize) {
|
||||
pub extern "C" fn carbonyl_output_get_size(size: *mut CSize) {
|
||||
let dst = unsafe { &mut *size };
|
||||
let src = output::size().unwrap().cast::<c_uint>();
|
||||
|
||||
@ -210,10 +203,7 @@ pub extern "C-unwind" fn carbonyl_output_get_size(size: *mut CSize) {
|
||||
/// This will block so the calling code should start and own a dedicated thread.
|
||||
/// It will panic if there is any error.
|
||||
#[no_mangle]
|
||||
pub extern "C-unwind" fn carbonyl_input_listen(
|
||||
renderer: *mut Renderer,
|
||||
delegate: *mut BrowserDelegate,
|
||||
) {
|
||||
pub extern "C" fn carbonyl_input_listen(renderer: *mut Renderer, delegate: *mut BrowserDelegate) {
|
||||
let char_width = 7;
|
||||
let char_height = 14;
|
||||
let (
|
||||
|
@ -1030,7 +1030,7 @@ index 35b1eda284846..a79c1aa1b6ae7 100644
|
||||
}
|
||||
|
||||
diff --git a/headless/BUILD.gn b/headless/BUILD.gn
|
||||
index bfae1e3290de0..7003948e30f6e 100644
|
||||
index bfae1e3290de0..ef0fedd6a473d 100644
|
||||
--- a/headless/BUILD.gn
|
||||
+++ b/headless/BUILD.gn
|
||||
@@ -453,8 +453,11 @@ component("headless_non_renderer") {
|
||||
@ -1045,12 +1045,17 @@ index bfae1e3290de0..7003948e30f6e 100644
|
||||
"//components/embedder_support",
|
||||
"//components/embedder_support:embedder_support",
|
||||
"//components/embedder_support/origin_trials",
|
||||
@@ -993,13 +996,20 @@ static_library("headless_shell_lib") {
|
||||
@@ -993,13 +996,25 @@ static_library("headless_shell_lib") {
|
||||
}
|
||||
|
||||
executable("headless_shell") {
|
||||
+ if (is_mac && !use_lld) {
|
||||
+ ldflags = [ "-Wl,-no_compact_unwind" ]
|
||||
+ } else if (is_linux) {
|
||||
+ ldflags = [
|
||||
+ "-Wl,-rpath=\$ORIGIN/.",
|
||||
+ "-Wl,-rpath-link=.",
|
||||
+ ]
|
||||
+ }
|
||||
+
|
||||
configs -= [ "//build/config/compiler:thinlto_optimize_default" ]
|
||||
|
@ -1,4 +1,3 @@
|
||||
#![feature(c_unwind)]
|
||||
pub mod browser;
|
||||
pub mod gfx;
|
||||
pub mod input;
|
||||
|
Loading…
Reference in New Issue
Block a user