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

clang predefines a wrong __ANDROID_API__ #6176

Closed
mame opened this issue Dec 24, 2020 · 3 comments
Closed

clang predefines a wrong __ANDROID_API__ #6176

mame opened this issue Dec 24, 2020 · 3 comments

Comments

@mame
Copy link

mame commented Dec 24, 2020

Problem description

The recent Termux's clang seems to define a __ANDROID_API__ macro as 24 by default, even though my Android version is 9.

Because many header files are using __ANDROID_API__ to determine whether a function prototype is declared or not, this mismatch makes it impossible to build some OSS packages. For example, I cannot build ruby.

compiling file.c
file.c:2880:27: error: implicit declaration of function 'lutimes' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if (v->follow) return lutimes(path, tvp);
                          ^
file.c:2880:27: note: did you mean 'utimes'?
/data/data/com.termux/files/usr/include/sys/time.h:47:5: note: 'utimes' declared here
int utimes(const char* __path, const struct timeval __times[2]);
    ^
1 error generated.

lutimes is declared only #if __ANDROID_API__ >= 26 in /data/data/com.termux/files/usr/include/sys/time.h.

Steps to reproduce

$ echo __ANDROID_API__ | clang -E - | tail -1
24
$ getprop ro.build.version.sdk
28

Expected behavior

$ echo __ANDROID_API__ | clang -E - | tail -1
28
$ getprop ro.build.version.sdk
28

Or, nothing defined by default is better than the wrong version.

Additional information

Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://main.termux-mirror.ml/ stable main
# science-repo (sources.list.d/science.list)
deb https://dl.bintray.com/grimler/science-packages-24 science stable
# game-repo (sources.list.d/game.list)
deb https://dl.bintray.com/grimler/game-packages-24 games stable
Updatable packages:
All packages up to date
Android version:
9
Kernel build information:
Linux localhost 4.4.148-perf+ #1 SMP PREEMPT Tue Sep 17 10:47:56 2019 aarch64 Android
Device manufacturer:
Sony
Device model:
SOV36
@ghost
Copy link

ghost commented Dec 24, 2020

That's intended behavior for now. Since all packages are built with API 24, clang will specify API 24 as well - hardcoded in headers.

Also this seems like a duplicate of #2469.

@ghost ghost closed this as completed Dec 24, 2020
@mame
Copy link
Author

mame commented Dec 24, 2020

Please, please reconsider. This is crucially incompatible with a typical build process by using configure.

configure determines if a function is available or not, by checking if the symbol is linkable or not. For example, since my device (Android 9) provides a symbol named lutimes, configure determines that it is available. However, the header file does not declare lutimes because __ANDROID_API__ is lower than the version where lutimes is available. This mismatch makes clang fail to compile many C programs as above.

I know the packages are built with API 24. But I think you don't use Termux's clang to build Termux packages. So, it is irrelevant. Clang in Termux should respect the device version instead of the package's.

Or, please predefine nothing. If so, I can work around the issue by manually specifying the device version as follows.

$ clang -D__ANDROID_API__=`getprop ro.build.version.sdk` foo.c

matzbot pushed a commit to ruby/ruby that referenced this issue Dec 24, 2020
The recent Termux's clang predefines `__ANDROID_API__` as a fixed number
24. However, when it is lower to the current device version, some
functions that "configure" detemines available are not declared
correctly in the header files.

This change forces to overwrite the predefined `__ANDROID_API__` macro
with the current device version.

ref: termux/termux-packages#6176
@mame
Copy link
Author

mame commented Dec 24, 2020

I've thought of the following workaround to force to overwrite the predefined macro without a warning, and pushed it to Ruby's configure. (Just FYI, the next major version of Ruby, 3.0.0, will be released tomorrow.)

$ clang -D__ANDROID_API__=`getprop ro.build.version.sdk` -Wno-macro-redefined

If this issue is not fixed, I believe many OSS developers have to use this kind of dirty hack if they want to build on Termux.
I truly hope it doesn't become so.

@ghost ghost locked and limited conversation to collaborators Oct 9, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant