Skip to content

Commit

Permalink
Add -ohos target support to autoconf (#458)
Browse files Browse the repository at this point in the history
* Add `-ohos` target support to autoconf

Add support for OpenHarmony OS.
A patch has been submitted upstream, pending review:
https://lists.gnu.org/archive/html/config-patches/2024-02/msg00008.html
After the patch has been merged upstream, we can update `config.sub` in
spidermonkey and drop this patch.

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

* Link `libc++` for ohos

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

---------

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
  • Loading branch information
jschwe committed Mar 21, 2024
1 parent b846d78 commit b695c63
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
9 changes: 5 additions & 4 deletions mozjs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ fn cc_flags() -> Vec<&'static str> {

let is_apple = target.contains("apple");
let is_freebsd = target.contains("freebsd");
let is_ohos = target.contains("ohos");

if is_apple || is_freebsd {
if is_apple || is_freebsd || is_ohos {
result.push("-stdlib=libc++");
}

Expand Down Expand Up @@ -244,7 +245,7 @@ fn build_spidermonkey(build_dir: &Path) {
cmd.env("MAKEFLAGS", makeflags);
}

if target.contains("apple") || target.contains("freebsd") {
if target.contains("apple") || target.contains("freebsd") || target.contains("ohos") {
cmd.env("CXXFLAGS", "-stdlib=libc++");
}

Expand Down Expand Up @@ -276,7 +277,7 @@ fn build_spidermonkey(build_dir: &Path) {
if target.contains("gnu") {
println!("cargo:rustc-link-lib=stdc++");
}
} else if target.contains("apple") || target.contains("freebsd") {
} else if target.contains("apple") || target.contains("freebsd") || target.contains("ohos") {
println!("cargo:rustc-link-lib=c++");
} else {
println!("cargo:rustc-link-lib=stdc++");
Expand Down Expand Up @@ -821,7 +822,7 @@ fn download_static_lib_binaries(archive: &Path, build_dir: &Path) {
if target.contains("gnu") {
println!("cargo:rustc-link-lib=stdc++");
}
} else if target.contains("apple") || target.contains("freebsd") {
} else if target.contains("apple") || target.contains("freebsd") || target.contains("ohos") {
println!("cargo:rustc-link-lib=c++");
} else {
println!("cargo:rustc-link-lib=stdc++");
Expand Down
21 changes: 21 additions & 0 deletions mozjs-sys/etc/patches/0030-autoconf-add-ohos.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/build/autoconf/config.sub b/build/autoconf/config.sub
--- a/build/autoconf/config.sub (revision 20f7934762a6a1d4751353c8d024a0185ba85547)
+++ b/build/autoconf/config.sub (revision 1d3dc1d7b53439ce8f799526ddbbe0f833b8ef0f)
@@ -1754,7 +1754,7 @@
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
- | fiwix* )
+ | fiwix* | ohos* )
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
@@ -1772,7 +1772,7 @@
# (given a valid OS), if there is a kernel.
case $kernel-$os in
linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* \
- | linux-musl* | linux-relibc* | linux-uclibc* )
+ | linux-musl* | linux-relibc* | linux-uclibc* | linux-ohos* )
;;
uclinux-uclibc* )
;;
4 changes: 2 additions & 2 deletions mozjs-sys/mozjs/build/autoconf/config.sub
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,7 @@ case $os in
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
| fiwix* )
| fiwix* | ohos* )
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
Expand All @@ -1772,7 +1772,7 @@ esac
# (given a valid OS), if there is a kernel.
case $kernel-$os in
linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* \
| linux-musl* | linux-relibc* | linux-uclibc* )
| linux-musl* | linux-relibc* | linux-uclibc* | linux-ohos* )
;;
uclinux-uclibc* )
;;
Expand Down

0 comments on commit b695c63

Please sign in to comment.