rocksdb icon indicating copy to clipboard operation
rocksdb copied to clipboard

Fix Android compilation

Open kasperisager opened this issue 1 year ago • 1 comments

I was seeing errors like these prior to this patch:

env/io_posix.cc:174:17: error: variable has incomplete type 'struct statfs'
  struct statfs buf;
env/io_posix.h:40:9: error: 'POSIX_MADV_NORMAL' macro redefined [-Werror,-Wmacro-redefined]
#define POSIX_MADV_NORMAL 0     /* [MC1] no further special treatment */

kasperisager avatar Aug 05 '24 13:08 kasperisager

I'm still seeing the following error for 32-bit builds:

env/io_posix.cc:1380:39: error: comparison of integers of different signs: 'long long' and 'unsigned long long' [-Werror,-Wsign-compare]
  file_stats.st_blksize !=

kasperisager avatar Aug 05 '24 13:08 kasperisager

This is still an issue as of v9.7.4: https://github.com/holepunchto/librocksdb/actions/runs/11954328841/job/33324183835

kasperisager avatar Nov 21 '24 13:11 kasperisager

@cbi42 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Nov 21 '24 18:11 facebook-github-bot

@cbi42 merged this pull request in facebook/rocksdb@a294529ca92050d5f480c2323a1a8a59eb9ce03f.

facebook-github-bot avatar Nov 27 '24 21:11 facebook-github-bot

This fix breaks the build for ANDROID_API < 23.

FAILED: CMakeFiles/rocksdb.dir/env/io_posix.cc.o 
/android-ndk-r27c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=x86_64-none-linux-android21 --sysroot=/android-ndk-r27c/toolchains/llvm/prebuilt/linux-x86_64/sysroot -DOS_ANDROID -DROCKSDB_AUXV_GETAUXVAL_PRESENT -DROCKSDB_FALLOCATE_PRESENT -DROCKSDB_LIB_IO_POSIX -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_NO_DYNAMIC_EXTENSION -DROCKSDB_PLATFORM_POSIX -DROCKSDB_SCHED_GETCPU_PRESENT -DZLIB -I/mnt/vcpkg-ci/b/rocksdb/src/v9.10.0-cb7ebd68b0.clean -I/mnt/vcpkg-ci/b/rocksdb/src/v9.10.0-cb7ebd68b0.clean/include -isystem /mnt/vcpkg-ci/installed/x64-android/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -frtti -fexceptions  -fPIC   -W -Wextra -Wall -pthread -Wsign-compare -Wshadow -Wno-unused-parameter -Wno-unused-variable -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers -Wno-strict-aliasing -Wno-invalid-offsetof -fno-limit-debug-info    -DROCKSDB_USE_RTTI -std=gnu++17 -fPIC -MD -MT CMakeFiles/rocksdb.dir/env/io_posix.cc.o -MF CMakeFiles/rocksdb.dir/env/io_posix.cc.o.d -o CMakeFiles/rocksdb.dir/env/io_posix.cc.o -c /mnt/vcpkg-ci/b/rocksdb/src/v9.10.0-cb7ebd68b0.clean/env/io_posix.cc
/mnt/vcpkg-ci/b/rocksdb/src/v9.10.0-cb7ebd68b0.clean/env/io_posix.cc:1022:41: error: use of undeclared identifier 'POSIX_MADV_NORMAL'
 1022 |       Madvise(mmapped_region_, length_, POSIX_MADV_NORMAL);
      |                                         ^
/mnt/vcpkg-ci/b/rocksdb/src/v9.10.0-cb7ebd68b0.clean/env/io_posix.cc:1025:41: error: use of undeclared identifier 'POSIX_MADV_RANDOM'
 1025 |       Madvise(mmapped_region_, length_, POSIX_MADV_RANDOM);
      |                                         ^
/mnt/vcpkg-ci/b/rocksdb/src/v9.10.0-cb7ebd68b0.clean/env/io_posix.cc:1028:41: error: use of undeclared identifier 'POSIX_MADV_SEQUENTIAL'
 1028 |       Madvise(mmapped_region_, length_, POSIX_MADV_SEQUENTIAL);
      |                                         ^
/mnt/vcpkg-ci/b/rocksdb/src/v9.10.0-cb7ebd68b0.clean/env/io_posix.cc:1031:41: error: use of undeclared identifier 'POSIX_MADV_WILLNEED'
 1031 |       Madvise(mmapped_region_, length_, POSIX_MADV_WILLNEED);
      |                                         ^
/mnt/vcpkg-ci/b/rocksdb/src/v9.10.0-cb7ebd68b0.clean/env/io_posix.cc:1034:41: error: use of undeclared identifier 'POSIX_MADV_DONTNEED'
 1034 |       Madvise(mmapped_region_, length_, POSIX_MADV_DONTNEED);
      |                                         ^
5 errors generated.

Possible fix:

 env/io_posix.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/env/io_posix.h b/env/io_posix.h
index 60788df9b..8ddfb3456 100644
--- a/env/io_posix.h
+++ b/env/io_posix.h
@@ -30,7 +30,7 @@
 // For non linux platform, the following macros are used only as place
 // holder.
 #if !(defined OS_LINUX) && !(defined OS_FREEBSD) && !(defined CYGWIN) && \
-    !(defined OS_AIX) && !(defined OS_ANDROID)
+    !(defined OS_AIX) && !(defined OS_ANDROID && __ANDROID_API__ >= 23)
 #define POSIX_FADV_NORMAL 0     /* [MC1] no further special treatment */
 #define POSIX_FADV_RANDOM 1     /* [MC1] expect random page refs */
 #define POSIX_FADV_SEQUENTIAL 2 /* [MC1] expect sequential page refs */

yurybura avatar Jan 04 '25 23:01 yurybura