This is an automated email from the ASF dual-hosted git repository.

gaurava pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new d1ce9656459 HDFS-17636. Don't add declspec for Windows (#7096)
d1ce9656459 is described below

commit d1ce9656459007b5c7f386fdafb018ca16ddf0c9
Author: Gautham B A <gautham.bangal...@gmail.com>
AuthorDate: Tue Oct 22 23:15:23 2024 +0530

    HDFS-17636. Don't add declspec for Windows (#7096)
    
    * Windows doesn't want the
      macro _JNI_IMPORT_OR_EXPORT_
      to be defined in the function
      definition. It fails to compile with
      the following error -
      "definition of dllimport function
      not allowed".
    * However, Linux needs it. Hence,
      we're going to add this macro
      based on the OS.
    * Also, we'll be compiling the `hdfs`
      target as an object library so that
      we can avoid linking to `jvm`
      library for `get_jni_test` target.
---
 .../src/main/native/libhdfs/CMakeLists.txt              | 12 +++++++++++-
 .../src/main/native/libhdfspp/tests/CMakeLists.txt      | 13 ++++++++++++-
 .../main/native/libhdfspp/tests/libhdfs_getjni_test.cc  | 17 +++++++++++++++--
 3 files changed, 38 insertions(+), 4 deletions(-)

diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/CMakeLists.txt
 
b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/CMakeLists.txt
index 958bdcf2a41..7094b49fd15 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/CMakeLists.txt
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/CMakeLists.txt
@@ -32,13 +32,23 @@ include_directories(
     ../libhdfspp/lib
 )
 
-hadoop_add_dual_library(hdfs
+set(HDFS_SOURCES
     exception.c
     jni_helper.c
     hdfs.c
     jclasses.c
     ${OS_DIR}/mutexes.c
     ${OS_DIR}/thread_local_storage.c
+)
+# We want to create an object library for hdfs
+# so that we can reuse it for the targets
+# (like get_jni_test), where we don't wish to
+# link to hdfs's publicly linked libraries
+# (like jvm)
+add_library(hdfs_obj OBJECT ${HDFS_SOURCES})
+set_target_properties(hdfs_obj PROPERTIES POSITION_INDEPENDENT_CODE ON)
+hadoop_add_dual_library(hdfs
+    $<TARGET_OBJECTS:hdfs_obj>
     $<TARGET_OBJECTS:x_platform_obj>
     $<TARGET_OBJECTS:x_platform_obj_c_api>
 )
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/CMakeLists.txt
 
b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/CMakeLists.txt
index 3e52c6d965a..3e3112181d1 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/CMakeLists.txt
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/CMakeLists.txt
@@ -74,8 +74,19 @@ add_executable(uri_test uri_test.cc)
 target_link_libraries(uri_test common gmock_main ${CMAKE_THREAD_LIBS_INIT})
 add_memcheck_test(uri uri_test)
 
+# We want to link to all the libraries of hdfs_static library,
+# except jvm.lib since we want to override some of the functions
+# provided by jvm.lib.
+get_target_property(HDFS_STATIC_LIBS_NO_JVM hdfs_static LINK_LIBRARIES)
+list(REMOVE_ITEM HDFS_STATIC_LIBS_NO_JVM ${JAVA_JVM_LIBRARY})
 add_executable(get_jni_test libhdfs_getjni_test.cc)
-target_link_libraries(get_jni_test gmock_main hdfs_static 
${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(get_jni_test
+    gmock_main
+    $<TARGET_OBJECTS:hdfs_obj>
+    $<TARGET_OBJECTS:x_platform_obj>
+    $<TARGET_OBJECTS:x_platform_obj_c_api>
+    ${HDFS_STATIC_LIBS_NO_JVM}
+    ${CMAKE_THREAD_LIBS_INIT})
 add_memcheck_test(get_jni get_jni_test)
 
 add_executable(remote_block_reader_test remote_block_reader_test.cc)
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/libhdfs_getjni_test.cc
 
b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/libhdfs_getjni_test.cc
index b2648da23bb..a4356a5255f 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/libhdfs_getjni_test.cc
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/libhdfs_getjni_test.cc
@@ -20,13 +20,26 @@
 #include <hdfs/hdfs.h>
 #include <jni.h>
 
+#ifdef WIN32
+#define DECLSPEC
+#else
+// Windows cribs when this is declared in the function definition,
+// However, Linux needs it.
+#define DECLSPEC _JNI_IMPORT_OR_EXPORT_
+#endif
+
+// hook the jvm runtime function. expect always failure
+DECLSPEC jint JNICALL JNI_GetDefaultJavaVMInitArgs(void*) {
+    return 1;
+}
+
 // hook the jvm runtime function. expect always failure
-_JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void*) {
+DECLSPEC jint JNICALL JNI_CreateJavaVM(JavaVM**, void**, void*) {
     return 1;
 }
 
 // hook the jvm runtime function. expect always failure
-_JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM**, void**, void*) {
+DECLSPEC jint JNICALL JNI_GetCreatedJavaVMs(JavaVM**, jsize, jsize*) {
     return 1;
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to