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

How to build jruby for a new platform --mips64el #4246

Open
vans88 opened this issue Oct 25, 2016 · 30 comments
Open

How to build jruby for a new platform --mips64el #4246

vans88 opened this issue Oct 25, 2016 · 30 comments

Comments

@vans88
Copy link

vans88 commented Oct 25, 2016

Environment

os.arch: mips64el
os.name: fedora21
os.kernel: 4.4.21 
Java version: 1.8.0_25
.... .... 

Expected Behavior

Recording the BUILDING.md file, run the command "./mvnw" and build successfully. but I can't find libjffi-1.2.so for my platform --mips64el-Linux/libjffi-1.2.so . Any suggestions?

Build results:
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] JRuby .............................................. SUCCESS [  6.560 s]
[INFO] JRuby Core ......................................... SUCCESS [10:24 min]
[INFO] JRuby Lib Setup .................................... SUCCESS [05:19 min]
[INFO] JRuby Truffle ...................................... SUCCESS [12:31 min]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 29:29 min
[INFO] Finished at: 2016-10-20T20:31:02+08:00
[INFO] Final Memory: 92M/3441M
[INFO] ------------------------------------------------------------------------

[root@dscn2 jruby]# find . -name *.so
./spec/ruby/fixtures/code/a/load_fixture.so
./spec/ruby/fixtures/code/load_fixture.ext.so
./spec/ruby/fixtures/code/load_fixture.so
./lib/jni/x86_64-Linux/libjffi-1.2.so
./lib/jni/x86_64-SunOS/libjffi-1.2.so
./lib/jni/i386-Linux/libjffi-1.2.so
./lib/jni/ppc64-Linux/libjffi-1.2.so
./lib/jni/i386-SunOS/libjffi-1.2.so
./lib/jni/sparcv9-SunOS/libjffi-1.2.so
./lib/jni/arm-Linux/libjffi-1.2.so
./lib/jni/aarch64-Linux/libjffi-1.2.so
./lib/jni/ppc64le-Linux/libjffi-1.2.so
./lib/jni/x86_64-FreeBSD/libjffi-1.2.so
./test/bogus.so

@enebo
Copy link
Member

enebo commented Oct 25, 2016

@vans88 unintuitively we build those as part of the https://github.com/jnr/jffi project. Once build on each platform we commit them since we are not cross-compiling all of these platforms.

@headius
Copy link
Member

headius commented Oct 25, 2016

Yes, @enebo is correct. We'd love to get MIPS support into jffi! Please open an issue there and try to build binaries for your platform. We'll incorporate them (and any necessary patches) into the next release.

@headius
Copy link
Member

headius commented Oct 25, 2016

Keep this open until we can update our jffi to one that has MIPS support.

@vans88
Copy link
Author

vans88 commented Oct 26, 2016

Many thanks to your reply, and your spirit of open source deeply encouraged me. I will clone the project ---https://github.com/jnr/jffi --- and build locally. if my get success, I will paste the modification at the later comment.Thank you again.

@vans88
Copy link
Author

vans88 commented Oct 26, 2016

@headius. I got and built the jffi source via the front link this morning, but my platform-related libjffi-1.2.so doesn't be generated.

Referencing the “aarch64” architecture from this link: [https://github.com/jnr/jffi/commit/d08b6d9b9ce818cd3d86a786d6ab9eef5aef77aa], I modified your source and generated a new patch.
jffi-for-mips64el.patch.txt

After the modifications, I built again and the situation was all the same. But I get some information may be related the case.

File list in jffi-native-1.2.7-5.fc21.loongson.mips64el rpm package

root@dscn2 ~]# rpm -ql jffi-native
/usr/lib/java/jffi-native.jar
/usr/lib/java/jffi/jffi-native.jar
/usr/lib64/jffi
/usr/lib64/jffi/mips64-Linux
**/usr/lib64/jffi/mips64-Linux/libjffi-1.2.so**
/usr/lib64/jffi/mips64-Linux/libjffi.so
/usr/share/doc/jffi-native
/usr/share/doc/jffi-native/COPYING.GPL
/usr/share/doc/jffi-native/COPYING.LESSER
/usr/share/doc/jffi-native/LICENSE
/usr/share/maven-metadata/jffi-native.xml

And in "archive" directory in jffi project, I found some jars:

[root@dscn2 archive]# pwd
/usr/local/jffi/archive
[root@dscn2 archive]# ls
jffi-aarch64-Linux.jar  jffi-i386-Linux.jar    jffi-ppc64le-Linux.jar  jffi-s390x-Linux.jar     jffi-x86_64-Linux.jar
jffi-arm-Linux.jar      jffi-i386-OpenBSD.jar  jffi-ppc64-Linux.jar    jffi-sparc-SunOS.jar     jffi-x86_64-OpenBSD.jar
[root@dscn2 archive]# pwd
/usr/local/jffi/archive
[root@dscn2 archive]# ls
jffi-aarch64-Linux.jar  jffi-i386-Linux.jar    jffi-ppc64le-Linux.jar  jffi-s390x-Linux.jar     jffi-x86_64-Linux.jar
jffi-arm-Linux.jar      jffi-i386-OpenBSD.jar  jffi-ppc64-Linux.jar    jffi-sparc-SunOS.jar     jffi-x86_64-OpenBSD.jar
jffi-Darwin.jar         jffi-i386-SunOS.jar    jffi-ppc-AIX.jar        jffi-sparcv9-SunOS.jar   jffi-x86_64-SunOS.jar
jffi-i386-FreeBSD.jar   jffi-i386-Windows.jar  jffi-ppc-Linux.jar      jffi-x86_64-FreeBSD.jar  jffi-x86_64-Windows.jar
[root@dscn2 archive]# jar xvf jffi-ppc64le-Linux.jar
  created: jni/
  created: jni/ppc64le-Linux/
 inflated: **jni/ppc64le-Linux/libjffi-1.2.so**

Make jffi-mips64el-Linux.jar
Make my platform-related jar archive file, through the following instructions.

[root@dscn2 archive]# mkdir jni
[root@dscn2 archive]# cp -rf  /usr/lib64/jffi/mips64-Linux jni
[root@dscn2 archive]# jar cf  jffi-mips64el-Linux.jar jni
[root@dscn2 archive]# ls  jffi-mips64el-Linux.jar 
 jffi-mips64el-Linux.jar 

Then I put file jffi-mips64el-Linux.jar into "archive" directory of jffi project. and build again. In "target" directory exists the following file list.

./target/jni/x86_64-Linux/libjffi-1.2.so
./target/jni/x86_64-SunOS/libjffi-1.2.so
./target/jni/i386-Linux/libjffi-1.2.so
./target/jni/ppc64-Linux/libjffi-1.2.so
./target/jni/i386-SunOS/libjffi-1.2.so
./target/jni/sparcv9-SunOS/libjffi-1.2.so
./target/jni/arm-Linux/libjffi-1.2.so
./target/jni/aarch64-Linux/libjffi-1.2.so
./target/jni/ppc64le-Linux/libjffi-1.2.so
./target/jni/x86_64-FreeBSD/libjffi-1.2.so
./target/jni/mips64el-Linux/libjffi-1.2.so
./archive/jni/ppc64le-Linux/libjffi-1.2.so

How do you think my behavior? I do not know whether this is correct.

@vans88
Copy link
Author

vans88 commented Oct 28, 2016

Currently, I find a dir named "mips" which contains the following files:

[root@dscn2 jffi]# ls -l /usr/local/jffi/jni/libffi/src/mips/
total 64
-rw-r--r-- 1 root root 26648 Oct 26 13:57 ffi.c
-rw-r--r-- 1 root root  6556 Oct 26 13:57 ffitarget.h
-rw-r--r-- 1 root root 14304 Oct 26 13:57 n32.S
-rw-r--r-- 1 root root 10586 Oct 26 13:57 o32.S

How do I use these file to get my platform supported?

@headius
Copy link
Member

headius commented Oct 30, 2016

I am confused...did it build your .so or not? It sounds like you did get it to build a jar, and that jar when put into archive/ unpacked properly into the jni dir.

As for the libffi mips code...I would have expected libffi's Makefile to have done the right thing here. If it's not, that's where you would want to investigate.

Do you know of any way to get access to a MIPS environment somewhere in the cloud?

@vans88
Copy link
Author

vans88 commented Oct 31, 2016

Er..., I have jffi-native rpm package installed in Fedora21 (mips64el), via the command "rpm -ql jffi-native", a file named "libjffi-1.2.so" shown as follows:

[root@dscn2 archive]# rpm -ql jffi-native
/usr/lib/java/jffi-native.jar
/usr/lib/java/jffi/jffi-native.jar
/usr/lib64/jffi
/usr/lib64/jffi/mips64-Linux
/usr/lib64/jffi/mips64-Linux/libjffi-1.2.so
/usr/lib64/jffi/mips64-Linux/libjffi.so
/usr/share/doc/jffi-native
/usr/share/doc/jffi-native/COPYING.GPL
/usr/share/doc/jffi-native/COPYING.LESSER
/usr/share/doc/jffi-native/LICENSE
/usr/share/maven-metadata/jffi-native.xml

Here I unpacked one of jars in "archive" directory, the same file named "libjffi-1.2.so" will be found in a platform-related DIR.

[root@dscn2 archive]# uname -a
Linux dscn2 4.4.21+ #3 SMP PREEMPT Wed Oct 12 09:14:23 CST 2016 mips64 mips64 mips64 GNU/Linux
[root@dscn2 archive]# uname -p
mips64
[root@dscn2 archive]# file /usr/lib64/jffi/mips64-Linux/libjffi-1.2.so
/usr/lib64/jffi/mips64-Linux/libjffi-1.2.so: ELF 64-bit LSB shared object, MIPS, MIPS64 rel2 version 1 (SYSV), dynamically linked, BuildID[sha1]=f599ca5881af7949a6e4551aac043384778ac9af, not stripped

Er..., There is a difference between CPU_TYPE and System.getProperty("os.arch"). The common names of cpu architecture is mips64, but os.arch obtained by function System.getProperty is mips64el. I just want to say the difference will impact some platform-related configuration here. For examples, I am not very clear the following configurations in file "build.xml".

Example 1:
 <condition property="run.jvm.model" value="-d64">
      <or>
        <os arch="amd64"/>
        <os arch="x86_64"/>
        <os arch="sparcv9"/>
        <os arch="s390x"/>
        <os arch="ppc64le"/>
        <os arch="mips64"/>  <!-should be mips64el or mips64 -->
        <os arch="aarch64"/>
      </or>
    </condition>

Example 2:
<condition property="platform.cpu" value="mips64">
      <or>
        <os arch="mips64"/> <!- should be mips64el or mips64 ?  -->
      </or>
    </condition>

@vans88
Copy link
Author

vans88 commented Oct 31, 2016

Could I use the jffi-native rpm package instead of building jffi source from github? if so, What should I use the rpm jffi-native to build jruby next? My final purpose is to build logstash, but when I run the command bin/logstash -e "", an error shown as follows:

[root@dscn2 logstash]# bin/logstash -e ""
Sending Logstash logs to /usr/local/logstash/logs which is now configured via log4j2.properties.
LoadError: Unsupported platform: unknown-linux
          require at org/jruby/RubyKernel.java:1040
          require at /usr/local/logstash/vendor/bundle/jruby/1.9/gems/polyglot-0.3.5/lib/polyglot.rb:65
           (root) at /usr/local/logstash/vendor/jruby/lib/ruby/shared/ffi/ffi.rb:69
          require at org/jruby/RubyKernel.java:1040
          require at /usr/local/logstash/vendor/bundle/jruby/1.9/gems/polyglot-0.3.5/lib/polyglot.rb:65
           (root) at /usr/local/logstash/vendor/jruby/lib/ruby/shared/ffi.rb:1
          require at org/jruby/RubyKernel.java:1040
          require at /usr/local/logstash/vendor/bundle/jruby/1.9/gems/polyglot-0.3.5/lib/polyglot.rb:65
           (root) at /usr/local/logstash/vendor/jruby/lib/ruby/shared/ffi.rb:1
           (root) at /usr/local/logstash/logstash-core/lib/logstash/util/prctl.rb:1
          require at org/jruby/RubyKernel.java:1040
          require at /usr/local/logstash/vendor/bundle/jruby/1.9/gems/polyglot-0.3.5/lib/polyglot.rb:65
             LibC at /usr/local/logstash/logstash-core/lib/logstash/util/prctl.rb:3
           (root) at /usr/local/logstash/logstash-core/lib/logstash/util/prctl.rb:2
           (root) at /usr/local/logstash/logstash-core/lib/logstash/util.rb:1
  set_thread_name at /usr/local/logstash/logstash-core/lib/logstash/util.rb:20
          execute at /usr/local/logstash/logstash-core/lib/logstash/runner.rb:204
           (root) at /usr/local/logstash/lib/bootstrap/environment.rb:68

through searching the keyword "LoadError: Unsupported platform: unknown-linux", I know the above error is caused by jruby' jffi doesn't support my platform mips64el. but I found the following information in README.md file that located in top DIR of logstash.

If you have a local JRuby installed you can force logstash to use your local JRuby instead of the embedded JRuby with theUSE_RUBY=1environment variable.

so, I need to build jruby and let logstash use a local JRuby instead of the embedded binary JRuby. But, I don't know how to use a local rpm package jffi-native to build jruby source code, or how to use libjffi-1.2.so file to build jffi source firstly? I think the key point is the relationship between jruby and jffi.

@vans88
Copy link
Author

vans88 commented Oct 31, 2016

I very sorry to tell the fact that there doesn't a way to get access to a MIPS environment in the cloud so far. I am also working for the mips cloud platform currently.

@headius Many thanks again. Every time you can give me some very useful suggestions.

@vans88
Copy link
Author

vans88 commented Nov 3, 2016

When using the jruby built from jruby project and set environment variable "USE_RUBY=1", I am getting the following errror:

Jruby version info:

[root@dscn2 bin]# echo $JRUBY_HOME
/usr/local/jruby

[root@dscn2 logstash]# jruby --version
*********************************
Platform.ARCH is:mips64el
*********************************
jruby 9.1.6.0-SNAPSHOT (2.3.1) 2016-11-01 b610805 OpenJDK 64-Bit Server VM 25.25-b02 on 1.8.0_25-rc17-b17 +jit [linux-mips64el]

logstash help command errror:

[root@dscn2 logstash]# bin/logstash --help
/usr/local/share/gems/gems/bundler-1.13.5/lib/bundler.rb:429:in `rescue in eval_gemspec':  (Bundler::GemspecError)
[!] There was an error while loading `logstash-core-plugin-api.gemspec`: The logstash-core-api need to be build on jruby. Bundler cannot continue.

 #  from /usr/local/logstash/logstash-core-plugin-api/logstash-core-plugin-api.gemspec:27
 #  -------------------------------------------
 #    else
 >      raise "The logstash-core-api need to be build on jruby"
 #    end
 #  -------------------------------------------
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler.rb:421:in `eval_gemspec'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler.rb:374:in `block in load_gemspec_uncached'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/shared_helpers.rb:54:in `chdir'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/shared_helpers.rb:54:in `block in chdir'
        from /usr/share/ruby/monitor.rb:211:in `mon_synchronize'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/shared_helpers.rb:53:in `chdir'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler.rb:369:in `load_gemspec_uncached'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler.rb:359:in `load_gemspec'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/source/path.rb:146:in `block in load_spec_files'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/source/path.rb:145:in `each'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/source/path.rb:145:in `load_spec_files'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/source/path.rb:95:in `local_specs'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/source/path.rb:103:in `specs'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/definition.rb:665:in `block in converge_locked_specs'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/definition.rb:654:in `each'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/definition.rb:654:in `converge_locked_specs'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/definition.rb:243:in `resolve'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/definition.rb:174:in `specs'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/definition.rb:233:in `specs_for'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/definition.rb:222:in `requested_specs'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/runtime.rb:118:in `block in definition_method'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler/runtime.rb:19:in `setup'
        from /usr/local/share/gems/gems/bundler-1.13.5/lib/bundler.rb:99:in `setup'
        from /usr/local/logstash/lib/bootstrap/bundler.rb:64:in `setup!'
        from /usr/local/logstash/lib/bootstrap/environment.rb:64:in `<main>'

@kszsa
Copy link

kszsa commented Sep 28, 2018

@vans88 ,I encountered the same problem. I want to know if your logstash transplant has been successful, How to solve it? thanks!

@trumanliu
Copy link

trumanliu commented Apr 10, 2019

@vans88 @kszsa +1,have you solved this problem?I am also trying to run logstash on a server with loongson cpu.

@trumanliu
Copy link

@kszsa +1,have you solved this problem?I am also trying to run logstash on a server with loongson cpu.

@headius
Copy link
Member

headius commented Apr 10, 2019

@trumanliu Would it be possible for you to try running JRuby (without logstash) on whatever MIPS system you're using? I'm not sure about the status of MIPS support in our native bits, but it would help if we could confirm that latest JRuby doesn't work on its own (logstash ships with older versions of JRuby usually).

@headius
Copy link
Member

headius commented Apr 11, 2019

FWIW one of the things that blocks some JRuby MIPS functionality is support for our native FFI library, jffi. Unfortunately the only PR we've gotten for MIPS has been abandoned: jnr/jffi#63

@maggiedot
Copy link

@headius I have the same problem on the loongson mips64 when run logstash 6.4.0. I installed latest JRuby 9.2.7.0, and output is below:

[root@localhost bin]# ./jruby -v
jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3 OpenJDK 64-Bit Server VM 25.192-b12 on 1.8.0_192-b12 +jit [linux-mips64el]
[root@localhost bin]# 
[root@localhost bin]# uname -a
Linux localhost.localdomain 3.10.0 #1 SMP PREEMPT Tue Mar 21 11:43:21 CST 2017 00012-g243a566 mips64 mips64 mips64 GNU/Linux

Wish it can help you.

@jackwang713
Copy link

I also encountered the same problem, on the mips64el platform jruby ffi can not run, I can provide a test platform for debugging, hoping to help improve these compatibility issues. If you need a remote connection, please contact me:
jackwang713@163.com

@headius
Copy link
Member

headius commented Aug 23, 2019

@jackwang713 That would be an enormous help! I will contact you by email.

@jackwang713
Copy link

@headius I don't know if you have received my mail. I've been waiting for two days.

@headius
Copy link
Member

headius commented Aug 29, 2019

@jackwang713 Apologies, your email got routed weirdly in my email, perhaps because of the attachment. I have received it and connected successfully!

@jackwang713
Copy link

@headius Has there been any progress on this issue? What else can I help do?

@headius
Copy link
Member

headius commented Sep 18, 2019

Sorry about the delay here.

JRuby master is now running with the jffi that has the FFI binary in place for mips64el-Linux, so that's part of the way.

I think we need to patch Platform.java to have MIPS as a platform entry (it already has Linux).

And then under lib/ruby/ffi/platform we need to get the appropriate files generated (or manually tweaked, since the generator seems broken currently) so that they have appropriate typedefs/sizes for all the listed types.

I'll see what I can do to get those typedefs generating.

@headius
Copy link
Member

headius commented Sep 18, 2019

@jackwang713 Ok, are you able to at least start up JRuby master (maybe from a nightly build at https://jruby.org/nightly)? If so, I need to know the output of this code:

puts ENV_JAVA['os.name']
puts ENV_JAVA['os.arch']

That should let us get Platform.java updated.

@jackwang713
Copy link

I don't know how to run the code you gave me. I made the following attempt.

[root@mips ~]# ruby -e "puts ENV_JAVA['os.name']"
Traceback (most recent call last):
-e:1:in `<main>': uninitialized constant ENV_JAVA (NameError)

Using java to obtain System.getProperty("os.name") and System.getProperty("os.arch"), I got the result.
OSName:Linux,OSArch:mips64el

@headius
Copy link
Member

headius commented Sep 23, 2019

@jackwang713 The command you ran shold have worked; I suspect it was run with CRuby instead of JRuby.

$ ruby -rpp -e 'pp ENV_JAVA.to_h'
{"java.runtime.name"=>"OpenJDK Runtime Environment",
 "jruby.home"=>"/Users/headius/projects/jruby",
 "sun.boot.library.path"=>
  "/Library/Java/JavaVirtualMachines/jdk-08-u202-b08-hotspot/Contents/Home/jre/lib",
 "java.vm.version"=>"25.202-b08",

Would it be possible to get access to your system again? You can send me an email with details.

headius added a commit to headius/jruby that referenced this issue Sep 23, 2019
@headius
Copy link
Member

headius commented Sep 23, 2019

@jackwang713 I have updated our set of types.conf files from https://github.com/ffi/ffi, which may get us a bit further in running properly on your system. Would you be able to test out the branch in #5886?

@jujiangtao
Copy link

Hello!I want to know whether jruby can be built on the platform --mips64el now.

@headius
Copy link
Member

headius commented Jan 26, 2021

@jujiangtao Greetings!

Much work has happened since this issue was last updated, and I believe JRuby itself supports mips64el fairly well at this point. I do not know whether that means JRuby will successfully build, since our build still uses a slightly older version of JRuby (for stability).

Could you work with me to finish this issue? We can start by having you run ./mvnw on a clean checkout of JRuby and go from there.

@headius
Copy link
Member

headius commented Jan 26, 2021

FWIW I would also like to understand the importance of building on mips64el. The binaries we distribute should work on mips64el without further building (we ship native bits for all supported platforms at once).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants