servo/ports/servoshell/build.rs
Jonathan Schwender 9455169813
Add OpenHarmony support to servoshell (#32594)
* Generate EGL bindings for ohos

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* Adjust servoshell `bin` error message for android/ohos

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* ohos: disable WebGL

offscreen buffers are not implemented yet on ohos.

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* Add OpenHarmony support to servoshell

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* Share ResourceReaderInstance

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* Share android/ohos HostTrait

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* Share servo glue

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

* Pass Init options from ArkTS to Servo

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* f rebase ResourceReaderMethods

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* fixup! Share ResourceReaderInstance

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* Fix typo

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* Update Cargo.lock

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* ohos: Move WebGL check to webgl thread

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* Remove commented code

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* Remove commented and duplicate / unused code

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

---------

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
2024-06-28 12:51:50 +00:00

91 lines
3.5 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::error::Error;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use gl_generator::{Api, Fallbacks, Profile, Registry};
use vergen::EmitBuilder;
// We can make this configurable in the future if different platforms start to have
// different needs.
fn generate_egl_bindings(out_dir: &Path) {
let mut file = File::create(out_dir.join("egl_bindings.rs")).unwrap();
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [])
.write_bindings(gl_generator::StaticStructGenerator, &mut file)
.unwrap();
println!("cargo:rustc-link-lib=EGL");
}
fn main() -> Result<(), Box<dyn Error>> {
// Cargo does not expose the profile name to crates or their build scripts,
// but we can extract it from OUT_DIR and set a custom cfg() ourselves.
let out = std::env::var("OUT_DIR")?;
let out = Path::new(&out);
let krate = out.parent().unwrap();
let build = krate.parent().unwrap();
let profile = build.parent().unwrap();
if profile.file_name().unwrap() == "production" {
println!("cargo:rustc-cfg=servo_production");
} else {
println!("cargo:rustc-cfg=servo_do_not_use_in_production");
}
// Note: We can't use `#[cfg(windows)]`, since that would check the host platform
// and not the target platform
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
if target_os == "windows" {
#[cfg(windows)]
{
let mut res = winres::WindowsResource::new();
res.set_icon("../../resources/servo.ico");
res.set_manifest_file("platform/windows/servo.exe.manifest");
res.compile().unwrap();
}
#[cfg(not(windows))]
panic!("Cross-compiling to windows is currently not supported");
} else if target_os == "macos" {
cc::Build::new()
.file("platform/macos/count_threads.c")
.compile("count_threads");
} else if target_os == "android" {
generate_egl_bindings(out);
// FIXME: We need this workaround since jemalloc-sys still links
// to libgcc instead of libunwind, but Android NDK 23c and above
// don't have libgcc. We can't disable jemalloc for Android as
// in 64-bit aarch builds, the system allocator uses tagged
// pointers by default which causes the assertions in SM & mozjs
// to fail. See https://github.com/servo/servo/issues/32175.
let mut libgcc = File::create(out.join("libgcc.a")).unwrap();
libgcc.write_all(b"INPUT(-lunwind)").unwrap();
println!("cargo:rustc-link-search=native={}", out.display());
} else if target_env == "ohos" {
generate_egl_bindings(out);
}
if let Err(error) = EmitBuilder::builder()
.fail_on_error()
.git_sha(true /* short */)
.emit()
{
println!(
"cargo:warning=Could not generate git version information: {:?}",
error
);
println!("cargo:rustc-env=VERGEN_GIT_SHA=nogit");
}
// On MacOS, all dylib dependencies are shipped along with the binary
// in the "/lib" directory. Setting the rpath here, allows the dynamic
// linker to locate them. See `man dyld` for more info.
if target_os == "macos" {
println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/lib/");
}
Ok(())
}