forked from servo/mozjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With these fixes, mozjs compiles successfully for the target 'aarch64-linux-ohos'. This also requires using a custom build of rustc with support for this target, and clang 10 from the ohos-sdk native toolchain. Additional wrappers are needed for the clang wrappers to be invoked with the sysroot from the SDK as well. Wrappers: https://doc.rust-lang.org/nightly/rustc/platform-support/openharmony.html ohos-sdk with clang toolchain: https://gitee.com/openharmony/docs/blob/master/en/release-notes/OpenHarmony-v3.2.2-release.md prebuilt rustc: clone https://gitee.com/openharmony/build.git and run the prebuilts_download.sh
- Loading branch information
Showing
4 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/bin/env python3 | ||
# 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 http://mozilla.org/MPL/2.0/. | ||
|
||
import os | ||
import platform | ||
import shutil | ||
import subprocess | ||
import sys | ||
|
||
from typing import Dict, Optional | ||
|
||
|
||
SUPPORTED_NDK_VERSION = '25' | ||
API_LEVEL = '30' | ||
|
||
|
||
def get_host_string() -> str: | ||
os_type = platform.system().lower() | ||
if os_type not in ["linux", "darwin"]: | ||
raise Exception("Android cross builds are only supported on Linux and macOS.") | ||
|
||
cpu_type = platform.machine().lower() | ||
host_suffix = "unknown" | ||
if cpu_type in ["i386", "i486", "i686", "i768", "x86"]: | ||
host_suffix = "x86" | ||
elif cpu_type in ["x86_64", "x86-64", "x64", "amd64"]: | ||
host_suffix = "x86_64" | ||
return os_type + "-" + host_suffix | ||
|
||
|
||
def check_output(*args, **kwargs) -> str: | ||
return subprocess.check_output(*args, **kwargs).decode("utf-8").strip() | ||
|
||
|
||
def get_target_from_args() -> Optional[str]: | ||
for arg in sys.argv: | ||
if arg.startswith("--target="): | ||
return arg.replace("--target=", "") | ||
return None | ||
|
||
|
||
def set_toolchain_binaries_in_env(toolchain_dir: str, env: Dict[str, str]): | ||
cc = os.path.join(toolchain_dir, "bin", "aarch64-unknown-linux-ohos-clang.sh") | ||
cxx = os.path.join(toolchain_dir, "bin", "aarch64-unknown-linux-ohos-clang++.sh") | ||
ar = check_output([cc, "--print-prog-name=llvm-ar"]) | ||
objcopy = check_output([cc, "--print-prog-name=llvm-objcopy"]) | ||
ranlib = check_output([cc, "--print-prog-name=llvm-ranlib"]) | ||
strip = check_output([cc, "--print-prog-name=llvm-strip"]) | ||
yasm = check_output([cc, "--print-prog-name=yasm"]) | ||
host_cc = env.get('HOST_CC') or shutil.which("clang") or shutil.which("gcc") | ||
host_cxx = env.get('HOST_CXX') or shutil.which("clang++") or shutil.which("g++") | ||
|
||
assert(host_cc) | ||
assert(host_cxx) | ||
|
||
env["AR"] = ar | ||
env["CC"] = cc | ||
env["CPP"] = f"{cc} -E" | ||
env["CXX"] = cxx | ||
env["HOST_CC"] = host_cc | ||
env["HOST_CXX"] = host_cxx | ||
env["OBJCOPY"] = objcopy | ||
env["RANLIB"] = ranlib | ||
env["STRIP"] = strip | ||
env["YASM"] = yasm | ||
|
||
|
||
def create_environment_for_build() -> Dict[str, str]: | ||
env = os.environ.copy() | ||
if "OHOS_NDK" not in env: | ||
raise Exception("Please set the OHOS_NDK_HOME environment variable.") | ||
|
||
ndk_dir = env["OHOS_NDK"] | ||
|
||
# Check if the NDK version is 21 | ||
# if not os.path.isfile(os.path.join(ndk_home_dir, 'source.properties')): | ||
# raise Exception( | ||
# "ANDROID_NDK should have file `source.properties`.\n" + | ||
# "The environment variable ANDROID_NDK_HOME may be set at a wrong path." | ||
# ) | ||
|
||
# with open(os.path.join(ndk_home_dir, 'source.properties'), encoding="utf8") as ndk_properties: | ||
# version_found = ndk_properties.readlines()[1].split(' = ')[1].split('.')[0] | ||
# if version_found != SUPPORTED_NDK_VERSION: | ||
# raise Exception( | ||
# "Servo and dependencies currently only support NDK version " + | ||
# f"{SUPPORTED_NDK_VERSION}. Found {version_found}" | ||
# ) | ||
|
||
# Add the toolchain to the path. | ||
host_string = get_host_string() | ||
toolchain_dir = os.path.join(ndk_dir, "llvm") | ||
sysroot_dir = os.path.join(ndk_dir, "sysroot") | ||
#env['PATH'] = os.pathsep.join([os.path.join(toolchain_dir, "bin"), env["PATH"]]) | ||
##bg_cxx_include_dir = os.path.join(ndk_dir, "llvm", "include", "libcxx-ohos", "include", "c++", "v1") | ||
##env["BINDGEN_EXTRA_CLANG_ARGS"] = "--sysroot " + sysroot_dir + " -I " + os.path.join(sysroot_dir, "usr", "include", "aarch64-linux-ohos") + " -I " + bg_cxx_include_dir | ||
env["LLVM_CONFIG_PATH"] = os.path.join(toolchain_dir, "bin", "llvm-config") | ||
set_toolchain_binaries_in_env(toolchain_dir, env) | ||
|
||
return env | ||
|
||
if __name__ == "__main__": | ||
completed_process = subprocess.run(sys.argv[1:], env=create_environment_for_build()) | ||
sys.exit(completed_process.returncode) |