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

Added LightGBM JAVA SWIG wrapper support for windows #1599

Merged
merged 1 commit into from Aug 28, 2018

Conversation

imatiach-msft
Copy link
Contributor

@imatiach-msft imatiach-msft commented Aug 22, 2018

Added LightGBM JAVA SWIG wrapper support for windows OS
TODO: Add to Mac OS (need to find a Mac to validate this on)

To validate on windows (note, you must have SWIG and java sdk installed and JAVA_HOME environment variable must be set):

mkdir build
cd build
cmake -DCMAKE_GENERATOR_PLATFORM=x64 -DUSE_SWIG=ON ..
cmake --build . --target ALL_BUILD --config Release

@StrikerRUS
Copy link
Collaborator

StrikerRUS commented Aug 22, 2018

Hi @imatiach-msft !

Is it possible to make the following minor fix for Linux in this PR too?

Also I think it'll good to set _lightgbm_swig as default target of make command when compiling with -DUSE_SWIG=ON flag, so that users will be able not to type make _lightgbm_swig, but just make.

And what about MinGW on Windows? Should it work potentially?

UPD:

TODO: Add to Mac OS (need to find a Mac to validate this on)

I believe that someone with macOS from #1326 can help to test.

@imatiach-msft
Copy link
Contributor Author

@StrikerRUS sorry I'm not sure how to fix the aliasing errors - all of the SWIG code is autogenerated. What is the preferred way to fix them, for example for this error:

/home/travis/build/Microsoft/LightGBM/build/java/lightgbmlibJAVA_wrap.cxx:615:29: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   arg3 = *(DatasetHandle *)&jarg3; 

my guess is that I should change the generated code to instead look like:

   arg3 = (DatasetHandle)jarg3;

@imatiach-msft
Copy link
Contributor Author

mingw should work but I haven't tested it yet

@imatiach-msft
Copy link
Contributor Author

@StrikerRUS I ran it with mingw on windows but I got this error, for some reason the swig dll was not generated (I do see the lightgbm dll however):

[100%] Linking CXX shared module ..\lib_lightgbm_swig.dll
process_begin: CreateProcess(NULL, cp C:/LightGBM/LightGBM/Release/*.dll com/microsoft/ml/lightgbm/windows/x86_64, ...)
failed.
make (e=2): The system cannot find the file specified.
mingw32-make[2]: *** [CMakeFiles\_lightgbm_swig.dir\build.make:89: ../lib_lightgbm_swig.dll] Error 2
mingw32-make[2]: *** Deleting file '../lib_lightgbm_swig.dll'
mingw32-make[1]: *** [CMakeFiles\Makefile2:68: CMakeFiles/_lightgbm_swig.dir/all] Error 2
mingw32-make: *** [Makefile:129: all] Error 2

@imatiach-msft
Copy link
Contributor Author

@StrikerRUS hmm, actually it seems that it is deleting the lib_lightgbm_swig.dll, it looks like when compiling in mingw there is no "Release" directory generated and this fails:
COMMAND cp "${PROJECT_SOURCE_DIR}/Release/*.dll" com/microsoft/ml/lightgbm/windows/x86_64

@StrikerRUS
Copy link
Collaborator

@imatiach-msft Yeah, MinGW places generated files right into the root folder of the project.

The exe and dll files will be in LightGBM/ folder.

(https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html#mingw-w64)

As for warnings, lets leave them for another PR.
Sorry, probably my #1599 (comment) was unclear, but under the minor fix I meant the following:

Also I think it'll good to set _lightgbm_swig as default target of make command when compiling with -DUSE_SWIG=ON flag, so that users will be able not to type make _lightgbm_swig, but just make.

@imatiach-msft
Copy link
Contributor Author

imatiach-msft commented Aug 24, 2018

@StrikerRUS I was getting errors even when I removed the Release dir last night, maybe it has to do with how I installed mingw, I specified threads=posix (the default) whereas I should have specified win32 (?)

@StrikerRUS
Copy link
Collaborator

StrikerRUS commented Aug 24, 2018

We run tests with POSIX threads too...
https://github.com/Microsoft/LightGBM/blob/dcf9ad2eb9c62dfe347cd249648459500df9d6e6/.appveyor.yml#L19

I was getting errors even when I removed the Release dir last night,

Which one?

@imatiach-msft
Copy link
Contributor Author

even if I do this it seems to complain:

  if(WIN32)
    if(MINGW OR CYGWIN)
        add_custom_command(TARGET _lightgbm_swig POST_BUILD
	        COMMAND "${Java_JAVAC_EXECUTABLE}" -d . java/*.java
	        COMMAND cp "*" "com"
	        COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com)
    else()
        add_custom_command(TARGET _lightgbm_swig POST_BUILD
	        COMMAND "${Java_JAVAC_EXECUTABLE}" -d . java/*.java
	        COMMAND cp "${PROJECT_SOURCE_DIR}/Release/*.dll" com/microsoft/ml/lightgbm/windows/x86_64
	        COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com)
    endif()
  else()
    add_custom_command(TARGET _lightgbm_swig POST_BUILD
	    COMMAND "${Java_JAVAC_EXECUTABLE}" -d . java/*.java
	    COMMAND cp "${PROJECT_SOURCE_DIR}/*.so" com/microsoft/ml/lightgbm/linux/x86_64
	    COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com)
  endif()

that's just copying everything to com folder... it seems it doesn't recognize com folder, weird

@imatiach-msft
Copy link
Contributor Author

I tried reinstalling mingw with win32 and running this but it didn't make a difference, seems that option doesn't have anything to do with paths (just with the threading library)

@StrikerRUS
Copy link
Collaborator

@imatiach-msft
Copy link
Contributor Author

imatiach-msft commented Aug 24, 2018

is the fix to remove git\usr\bin from path?

@imatiach-msft
Copy link
Contributor Author

also, how do I set:

set _lightgbm_swig as default target of make command

I tried the following:
add_library(_lightgbm_swig ${SOURCES})
the build complained though

@StrikerRUS
Copy link
Collaborator

Yep!

Are you running tests at Appveyor, not locally?

@imatiach-msft
Copy link
Contributor Author

even when I removed from path and rebuilt I still got the error, here is my path:

PS C:\LightGBM\LightGBM\build> $env:PATH
C:\Program Files\Docker\Docker\Resources\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Ora
cle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:
\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Users\ilmat\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Prog
ram Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\Git\mi
ngw64\bin;C:\Program Files\dotnet\;C:\Program Files\SourceGear\Common\DiffMerge\;C:\Program Files\CMake\bin;C:\WINDOWS\S
ystem32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\
Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\
DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Users\ilmat\AppData\Local\Cont
inuum\Miniconda3;C:\Users\ilmat\AppData\Local\Continuum\Miniconda3\Scripts;C:\Users\ilmat\AppData\Local\Continuum\Minico
nda3\Library\bin;C:\Users\ilmat\AppData\Local\Microsoft\WindowsApps;C:\Users\ilmat\AppData\Roaming\npm;C:\Users\ilmat\Ap
pData\Local\Programs\Fiddler;C:\Users\ilmat\Documents\swigwin-3.0.12;C:\Users\ilmat\AppData\Local\Microsoft\WindowsApps;
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin

this is the error:

process_begin: CreateProcess(NULL, cp C:/LightGBM/LightGBM/*.dll com/microsoft/ml/lightgbm/windows/x86_64, ...) failed.
make (e=2): The system cannot find the file specified.
mingw32-make[2]: *** [CMakeFiles\_lightgbm_swig.dir\build.make:89: ../lib_lightgbm_swig.dll] Error 2
mingw32-make[2]: *** Deleting file '../lib_lightgbm_swig.dll'
mingw32-make[1]: *** [CMakeFiles\Makefile2:68: CMakeFiles/_lightgbm_swig.dir/all] Error 2
mingw32-make: *** [Makefile:129: all] Error 2

@imatiach-msft
Copy link
Contributor Author

imatiach-msft commented Aug 24, 2018

Are you running tests at Appveyor, not locally?

I'm not running any tests I'm just trying to build lightgbm locally. I'm just running everything through powershell on my local machine.

@StrikerRUS
Copy link
Collaborator

Maybe this one item in your PATH interrupts:

C:\Program Files\Git\mingw64\bin

?

I'm just running everything through powershell.

Got it! That fix affects only our test builds at Appveyor. It's like a tests script for CI service, and it's not connected with the LightGBM building process itself.

@imatiach-msft
Copy link
Contributor Author

still failing, this is the new path:

PS C:\LightGBM\LightGBM\build> $env:PATH
C:\Program Files\Docker\Docker\Resources\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Ora
cle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:
\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Users\ilmat\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Prog
ram Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\dotnet
\;C:\Program Files\SourceGear\Common\DiffMerge\;C:\Program Files\CMake\bin;C:\WINDOWS\System32\OpenSSH\;C:\Program Files
\Microsoft VS Code\bin;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86
)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\
Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Users\ilmat\AppData\Local\Continuum\Miniconda3;C:\Users\ilmat\A
ppData\Local\Continuum\Miniconda3\Scripts;C:\Users\ilmat\AppData\Local\Continuum\Miniconda3\Library\bin;C:\Users\ilmat\A
ppData\Local\Microsoft\WindowsApps;C:\Users\ilmat\AppData\Roaming\npm;C:\Users\ilmat\AppData\Local\Programs\Fiddler;C:\U
sers\ilmat\Documents\swigwin-3.0.12;C:\Users\ilmat\AppData\Local\Microsoft\WindowsApps;C:\Program Files\mingw-w64\x86_64
-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin

same error:

process_begin: CreateProcess(NULL, cp C:/LightGBM/LightGBM/*.dll com/microsoft/ml/lightgbm/windows/x86_64, ...) failed.
make (e=2): The system cannot find the file specified.
mingw32-make[2]: *** [CMakeFiles\_lightgbm_swig.dir\build.make:89: ../lib_lightgbm_swig.dll] Error 2
mingw32-make[2]: *** Deleting file '../lib_lightgbm_swig.dll'
mingw32-make[1]: *** [CMakeFiles\Makefile2:68: CMakeFiles/_lightgbm_swig.dir/all] Error 2
mingw32-make: *** [Makefile:129: all] Error 2

@StrikerRUS
Copy link
Collaborator

My assumption is that it cannot find cp command rather than com or any other folder...

Try to set C:\Program Files\mingw-w64\x86_64 -8.1.0-posix-seh-rt_v6-rev0\mingw64\bin as first entry in the PATH.

@imatiach-msft
Copy link
Contributor Author

here's the new path:

PS C:\LightGBM\LightGBM\build> $env:Path
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;C:\Program Files\Docker\Docker\Resources\bin;C:
\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOW
S;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\110\Tools\B
inn\;C:\Users\ilmat\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;
C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\dotnet\;C:\Program Files\SourceGear\Common\DiffMerge\
;C:\Program Files\CMake\bin;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files (x86)\M
icrosoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Progr
am Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementS
tudio\;C:\Users\ilmat\AppData\Local\Continuum\Miniconda3;C:\Users\ilmat\AppData\Local\Continuum\Miniconda3\Scripts;C:\Us
ers\ilmat\AppData\Local\Continuum\Miniconda3\Library\bin;C:\Users\ilmat\AppData\Local\Microsoft\WindowsApps;C:\Users\ilm
at\AppData\Roaming\npm;C:\Users\ilmat\AppData\Local\Programs\Fiddler;C:\Users\ilmat\Documents\swigwin-3.0.12;C:\Users\il
mat\AppData\Local\Microsoft\WindowsApps

same error:

[100%] Linking CXX shared module ..\lib_lightgbm_swig.dll
process_begin: CreateProcess(NULL, cp C:/LightGBM/LightGBM/*.dll com/microsoft/ml/lightgbm/windows/x86_64, ...) failed.
make (e=2): The system cannot find the file specified.
mingw32-make[2]: *** [CMakeFiles\_lightgbm_swig.dir\build.make:89: ../lib_lightgbm_swig.dll] Error 2
mingw32-make[2]: *** Deleting file '../lib_lightgbm_swig.dll'
mingw32-make[1]: *** [CMakeFiles\Makefile2:68: CMakeFiles/_lightgbm_swig.dir/all] Error 2
mingw32-make: *** [Makefile:129: all] Error 2

@imatiach-msft
Copy link
Contributor Author

imatiach-msft commented Aug 24, 2018

also, any tips on how to do this

set _lightgbm_swig as default target of make command

looking at swig docs it doesn't mention adding a target anywhere

@StrikerRUS
Copy link
Collaborator

I think it's the same issue here https://stackoverflow.com/questions/33674973/makefile-error-make-e-2-the-system-cannot-find-the-file-specified

Can you try to specify the full path of cp?

@StrikerRUS
Copy link
Collaborator

How about to avoid cp with CMake equivalent?

https://stackoverflow.com/a/46660887

@imatiach-msft
Copy link
Contributor Author

FYI this is the error for the add_library call:

CMake Error at C:/Program Files/CMake/share/cmake-3.11/Modules/UseSWIG.cmake:323 (add_library):
  add_library cannot create target "_lightgbm_swig" because another target
  with the same name already exists.  The existing target is a static library
  created in source directory "C:/LightGBM/LightGBM".  See documentation for
  policy CMP0002 for more details.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.11/Modules/UseSWIG.cmake:273 (swig_add_library)
  CMakeLists.txt:179 (swig_add_module)

@StrikerRUS
Copy link
Collaborator

Latest CMake https://cmake.org/cmake/help/v3.12/module/UseSWIG.html

Note The variable SWIG_MODULE__REAL_NAME will be set to the name of the swig module target library. This variable is useless if variable UseSWIG_TARGET_NAME_PREFERENCE is set to STANDARD.

@StrikerRUS
Copy link
Collaborator

Stupid proposal 😄 , but maybe just _lightgbm_swig -> _lightgbm?
https://github.com/Microsoft/LightGBM/blob/dcf9ad2eb9c62dfe347cd249648459500df9d6e6/CMakeLists.txt#L171

@StrikerRUS
Copy link
Collaborator

@imatiach-msft
Copy link
Contributor Author

imatiach-msft commented Aug 24, 2018

I got this error when changing _lightgbm_swig -> _lightgbm:

CMake Error at C:/Program Files/CMake/share/cmake-3.11/Modules/UseSWIG.cmake:323 (add_library):
  add_library cannot create target "_lightgbm" because another target with
  the same name already exists.  The existing target is a shared library
  created in source directory "C:/LightGBM/LightGBM".  See documentation for
  policy CMP0002 for more details.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.11/Modules/UseSWIG.cmake:273 (swig_add_library)
  CMakeLists.txt:178 (swig_add_module)


CMake Error: File C:/LightGBM/LightGBM/*.dll does not exist.
CMake Error at CMakeLists.txt:187 (configure_file):
  configure_file Problem configuring file


-- Configuring incomplete, errors occurred!
See also "C:/LightGBM/LightGBM/build/CMakeFiles/CMakeOutput.log".

with the following code:

if(USE_SWIG)
  set_property(SOURCE swig/lightgbmlib.i PROPERTY CPLUSPLUS ON)
  LIST(APPEND swig_options -package com.microsoft.ml.lightgbm)
  set_property(SOURCE swig/lightgbmlib.i PROPERTY SWIG_FLAGS "${swig_options}")
  swig_add_module(_lightgbm java swig/lightgbmlib.i)
  if(MSVC)
    set_target_properties(_lightgbm_swig PROPERTIES OUTPUT_NAME "lib_lightgbm_swig")
  endif(MSVC)
  if(WIN32)
    if(MINGW OR CYGWIN)
        add_custom_command(TARGET _lightgbm POST_BUILD
	        COMMAND "${Java_JAVAC_EXECUTABLE}" -d . java/*.java
	        COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com)
		configure_file("${PROJECT_SOURCE_DIR}/*.dll" com/microsoft/ml/lightgbm/windows/x86_64 COPYONLY)
    else()
        add_custom_command(TARGET _lightgbm POST_BUILD
	        COMMAND "${Java_JAVAC_EXECUTABLE}" -d . java/*.java
	        COMMAND cp "${PROJECT_SOURCE_DIR}/Release/*.dll" com/microsoft/ml/lightgbm/windows/x86_64
	        COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com)
    endif()
  else()
    add_custom_command(TARGET _lightgbm POST_BUILD
	    COMMAND "${Java_JAVAC_EXECUTABLE}" -d . java/*.java
	    COMMAND cp "${PROJECT_SOURCE_DIR}/*.so" com/microsoft/ml/lightgbm/linux/x86_64
	    COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com)
  endif()
endif(USE_SWIG)

@imatiach-msft
Copy link
Contributor Author

the configure_file command doesn't seem to work because the cp needs to be done as part of the POST_BUILD task, hmmm

@imatiach-msft
Copy link
Contributor Author

I wonder if the fact that I have bash.exe in C:\Windows\System32 is messing mingw up (bash on windows)

@imatiach-msft
Copy link
Contributor Author

imatiach-msft commented Aug 25, 2018

@StrikerRUS how did you build them? I had the lib_ in front:

mkdir build
cd build
cmake -G "MinGW Makefiles" -DUSE_SWIG=ON ..
mingw32-make.exe -j4

did you have this fix included:

if(MSVC) 
    set_target_properties(_lightgbm_swig PROPERTIES OUTPUT_NAME "lib_lightgbm_swig") 
  endif(MSVC) 

@StrikerRUS
Copy link
Collaborator

did you have this fix included:

Yep. But it's for Visual Studio case and we're speaking about MinGW now.

BTW, I have no idea why it works here for WinGW without specifying SWIG target

mingw32-make.exe -j4

At Travis CI service this command didn't build SWIG part, only ordinal LightGBM dll. After changing to make _lightgbm_swig -j4 everything was OK.

@StrikerRUS
Copy link
Collaborator

StrikerRUS commented Aug 25, 2018

I don't know, maybe something wrong with my environment, but I think it's better to prevent build failures for other users who may have the same problems:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index da249c2..cab1a2a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -177,15 +177,13 @@ if(USE_SWIG)
   set_property(SOURCE swig/lightgbmlib.i PROPERTY SWIG_FLAGS "${swig_options}")
   swig_add_module(_lightgbm_swig java swig/lightgbmlib.i)
   swig_link_libraries(_lightgbm_swig _lightgbm)
-  if(MSVC)
-    set_target_properties(_lightgbm_swig PROPERTIES OUTPUT_NAME "lib_lightgbm_swig")
-  endif(MSVC)
   if(WIN32)
+    set_target_properties(_lightgbm_swig PROPERTIES OUTPUT_NAME "lib_lightgbm_swig")
     if(MINGW OR CYGWIN)

What do you think?

@StrikerRUS
Copy link
Collaborator

StrikerRUS commented Aug 25, 2018

I've found the reason of the lib prefix! 🌟
https://gitlab.kitware.com/cmake/cmake/merge_requests/1871/diffs

The :module:UseSWIG module :command:swig_add_library command
(and legacy swig_add_module command) now set the prefix of
Java modules to "" for MINGW, MSYS, and CYGWIN environments.

Now this change seems to be reasonable (and even required).

Due to the latest JAVA environment I had to install latest CMake (3.12). That's why we have different behavior with you.

@imatiach-msft
Copy link
Contributor Author

you're change seems reasonable, I'll update the PR, good find!

@imatiach-msft
Copy link
Contributor Author

"At Travis CI service this command didn't build SWIG part, only ordinal LightGBM dll. After changing to make _lightgbm_swig -j4 everything was OK."
Sorry, maybe I am misunderstanding, but did the Travis CI server specify the SWIG flag also, eg:
cmake -G "MinGW Makefiles" -DUSE_SWIG=ON ..
and even with that it did not build the lib_lightgbm_swig dll? strange, it works for me.
is this comment resolved by setting the output with the new version of cmake, or is this still an issue that needs to be looked into?

@StrikerRUS
Copy link
Collaborator

StrikerRUS commented Aug 25, 2018

You are right.

cmake -DUSE_SWIG=ON ..  
make

didn't work, but

cmake -DUSE_SWIG=ON ..  
make _lightgbm_swig

worked fine. But it was a month ago at Travis.

I didn't re-checked this and thought that the same situation is with MinGW too. However, yesterday I discovered that

cmake -DUSE_SWIG=ON -G"MinGW Makefiles" ..  
mingw32-make

works OK.

Let me do tests again and I'll back to you with results.
However, it seems to be very minor issue, because it's enough to provide mingw32-make _lightgbm_swig command for users and everything will be OK in 100% cases.

PS. My intuition is that it's CMake version issue again (at Travis it's extremely old).

UPD:
So many confusing commits related to SWIG module target!..

UseSWIG: Do not set PREFIX property for SHARED and STATIC lua libraries
UseSWIG: Fall back to empty PREFIX for unknown languages
UseSWIG: fix prefix library for Java on Windows
UseSWIG: reintroduce legacy target name management
UseSWIG: add policy to manage target naming strategy
...

https://github.com/Kitware/CMake/commits/master/Modules/UseSWIG.cmake
😮

CMakeLists.txt Outdated
COMMAND "${Java_JAVAC_EXECUTABLE}" -d . java/*.java
COMMAND cp "${PROJECT_SOURCE_DIR}/*.so" com/microsoft/ml/lightgbm/linux/x86_64
COMMAND "${Java_JAR_EXECUTABLE}" -cf lightgbmlib.jar com)
set_target_properties(_lightgbm_swig PROPERTIES OUTPUT_NAME "lib_lightgbm_swig")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please write a comment here, because someone might want to "optimize" this line in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did my comment make sense? what were you specifically looking for in the comment?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your comment is pretty good! Many thanks!

@StrikerRUS
Copy link
Collaborator

StrikerRUS commented Aug 25, 2018

I'm so sorry, @imatiach-msft !

I've found that a month ago I ran tests with make _lightgbm, not just make command.

I've re-tested at Travis and everything is OK with default targets. Sorry again.

@StrikerRUS
Copy link
Collaborator

Unfortunately, I've found a new bug. 😢
Please take a look at logs:
https://travis-ci.org/Microsoft/LightGBM/jobs/420619579#L1749

CMake 3.9.2 on Ubuntu produces liblib_lightgbm_swig.so.
Taking into account changing default behavior from version to version, I think that we cannot rely only on

set_target_properties(_lightgbm_swig PROPERTIES OUTPUT_NAME "lib_lightgbm_swig") 

and need explicitly disable prefix somehow...

@imatiach-msft
Copy link
Contributor Author

maybe only execute that line on windows?

@imatiach-msft
Copy link
Contributor Author

hmm, I updated the PR, is there a particular corner case that I am missing?

@StrikerRUS
Copy link
Collaborator

StrikerRUS commented Aug 26, 2018

I'm afraid that it'll produce liblib_lightgbm_swig.so name with old CMake version and MinGW. Can you please check it with your CMake 3.11?

@StrikerRUS
Copy link
Collaborator

StrikerRUS commented Aug 26, 2018

What do you think about the following "hack", which will hardcode the name and supposed to work for all CMake versions and platforms?
Inspired by this Kitware/CMake@51b6426#diff-276855d5d58f8f4c0de1b0132c887f05

<for all platforms>
set_target_properties(_lightgbm_swig PROPERTIES PREFIX "")
set_target_properties(_lightgbm_swig PROPERTIES OUTPUT_NAME "lib_lightgbm_swig") 

(Not sure about the order of these commands)

@imatiach-msft
Copy link
Contributor Author

"old CMake version and MinGW"
I don't think we should worry about older versions, the solution is usually to upgrade to latest stable version (or, we might be able to add version-specific code, but I think that is too much for the SWIG feature).
I like this idea, will update the code. If it works for older versions of CMake that's a great bonus.

@StrikerRUS
Copy link
Collaborator

Also, it'll protect us from any future changes in prefix policy. 💪

@imatiach-msft
Copy link
Contributor Author

this works great! I verified this on:
windows build without mingw
windows build with mingw
linux (ubuntu 16.04) build
in all cases the swig [so/dll] was built and placed in the correct directory :)

@StrikerRUS
Copy link
Collaborator

Let me enhance the list:

  • Windows with MinGW (CMake 3.12, SWIG 3.0.12);
  • Linux (Ubuntu 14.04) (CMake 3.9.2, SWIG 2.0.11)

Copy link
Collaborator

@StrikerRUS StrikerRUS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much, @imatiach-msft !

ping @guolinke

@guolinke
Copy link
Collaborator

Thank you very much !

@daniloascione
Copy link

Thank you for this one. I could help here to test/validate on Mac.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants