os72 / protoc-jar

Protocol Buffers protobuf compiler - multi-platform executable protoc JAR and API
Apache License 2.0
137 stars 82 forks source link

Error running on Alpine #15

Open zikolach opened 7 years ago

zikolach commented 7 years ago

No sure at all if it is an issue with protoc-jar - just noticed strange behaviour running build on Alpine.

java.lang.RuntimeException: error occurred while compiling protobuf files: Cannot run program "/tmp/protocjar4371571502781337723/bin/protoc.exe": error=2, No such file or directory

In case anyone will have trouble there is workaround:

# docker run -it --rm alpine sh
/ # apk add --no-cache curl
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
(1/4) Installing ca-certificates (20161130-r0)
(2/4) Installing libssh2 (1.7.0-r2)
(3/4) Installing libcurl (7.52.1-r1)
(4/4) Installing curl (7.52.1-r1)
Executing busybox-1.25.1-r0.trigger
Executing ca-certificates-20161130-r0.trigger
OK: 5 MiB in 15 packages
/ # curl -sL https://github.com/os72/protoc-jar/raw/v3.1.0.2/bin_261/linux/protoc > protoc && chmod +x protoc
/ # ./protoc --version
sh: ./protoc: not found
/ # ldd protoc
    /lib64/ld-linux-x86-64.so.2 (0x562ae150e000)
    libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x562ae150e000)
Error loading shared library libstdc++.so.6: No such file or directory (needed by protoc)
    libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x562ae150e000)
Error loading shared library libgcc_s.so.1: No such file or directory (needed by protoc)
    libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x562ae150e000)
Error relocating protoc: _ZNSs6appendEPKcm: symbol not found
Error relocating protoc: _ZSt20__throw_length_errorPKc: symbol not found
Error relocating protoc: _ZNSolsEi: symbol not found
Error relocating protoc: _ZSt18_Rb_tree_decrementPKSt18_Rb_tree_node_base: symbol not found
Error relocating protoc: _ZNSs9_M_mutateEmmm: symbol not found
Error relocating protoc: __strtof_internal: symbol not found
Error relocating protoc: _ZNSs6appendERKSsmm: symbol not found
Error relocating protoc: __cxa_guard_acquire: symbol not found
Error relocating protoc: _ZNSsC1EPKcmRKSaIcE: symbol not found
Error relocating protoc: _ZNSs7replaceEmmPKcm: symbol not found
Error relocating protoc: _Znam: symbol not found
Error relocating protoc: _ZdlPv: symbol not found
Error relocating protoc: _ZNSs7reserveEm: symbol not found
Error relocating protoc: _ZNKSs5rfindEcm: symbol not found
Error relocating protoc: __cxa_rethrow: symbol not found
Error relocating protoc: _ZNSt8ios_base4InitC1Ev: symbol not found
Error relocating protoc: _ZSt18_Rb_tree_decrementPSt18_Rb_tree_node_base: symbol not found
Error relocating protoc: _ZNSs4_Rep9_S_createEmmRKSaIcE: symbol not found
Error relocating protoc: _ZnwmRKSt9nothrow_t: symbol not found
Error relocating protoc: _ZNSsC1ERKSs: symbol not found
Error relocating protoc: _ZSt20__throw_out_of_rangePKc: symbol not found
Error relocating protoc: _ZNSi4readEPcl: symbol not found
Error relocating protoc: _ZNSt8ios_base4InitD1Ev: symbol not found
Error relocating protoc: _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc: symbol not found
Error relocating protoc: _ZNSo5writeEPKcl: symbol not found
Error relocating protoc: _ZNSsC1EmcRKSaIcE: symbol not found
Error relocating protoc: _ZNSsD1Ev: symbol not found
Error relocating protoc: _ZNKSs17find_first_not_ofEPKcmm: symbol not found
Error relocating protoc: _ZNSs4_Rep10_M_destroyERKSaIcE: symbol not found
Error relocating protoc: _ZNKSs13find_first_ofEPKcmm: symbol not found
Error relocating protoc: __cxa_guard_release: symbol not found
Error relocating protoc: _ZNSs6insertEmPKcm: symbol not found
Error relocating protoc: _ZSt18_Rb_tree_incrementPKSt18_Rb_tree_node_base: symbol not found
Error relocating protoc: _ZNSs6appendEmc: symbol not found
Error relocating protoc: _ZNKSs4findEcm: symbol not found
Error relocating protoc: _ZNKSs7compareEPKc: symbol not found
Error relocating protoc: _ZNSsC1EPKcRKSaIcE: symbol not found
Error relocating protoc: __cxa_call_unexpected: symbol not found
Error relocating protoc: _ZNKSs4findEPKcmm: symbol not found
Error relocating protoc: __dynamic_cast: symbol not found
Error relocating protoc: __cxa_pure_virtual: symbol not found
Error relocating protoc: __strtod_internal: symbol not found
Error relocating protoc: _ZdlPvRKSt9nothrow_t: symbol not found
Error relocating protoc: _ZSt29_Rb_tree_insert_and_rebalancebPSt18_Rb_tree_node_baseS0_RS_: symbol not found
Error relocating protoc: _ZStlsIcSt11char_traitsIcESaIcEERSt13basic_ostreamIT_T0_ES7_RKSbIS4_S5_T1_E: symbol not found
Error relocating protoc: _ZSt28_Rb_tree_rebalance_for_erasePSt18_Rb_tree_node_baseRS_: symbol not found
Error relocating protoc: __cxa_allocate_exception: symbol not found
Error relocating protoc: _ZNSs6assignEPKcm: symbol not found
Error relocating protoc: _ZNSt9exceptionD2Ev: symbol not found
Error relocating protoc: __cxa_free_exception: symbol not found
Error relocating protoc: _ZNSs6assignERKSs: symbol not found
Error relocating protoc: _ZSt19__throw_logic_errorPKc: symbol not found
Error relocating protoc: _ZdaPv: symbol not found
Error relocating protoc: __cxa_throw: symbol not found
Error relocating protoc: _ZSt18_Rb_tree_incrementPSt18_Rb_tree_node_base: symbol not found
Error relocating protoc: __cxa_end_catch: symbol not found
Error relocating protoc: _ZSt17__throw_bad_allocv: symbol not found
Error relocating protoc: _ZNKSs7compareEmmRKSs: symbol not found
Error relocating protoc: _ZNSs6resizeEmc: symbol not found
Error relocating protoc: _ZNSs14_M_replace_auxEmmmc: symbol not found
Error relocating protoc: _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_: symbol not found
Error relocating protoc: __cxa_begin_catch: symbol not found
Error relocating protoc: __gxx_personality_v0: symbol not found
Error relocating protoc: _Znwm: symbol not found
Error relocating protoc: _ZNSsC1ERKSsmm: symbol not found
Error relocating protoc: _Unwind_Resume: symbol not found
Error relocating protoc: _ZN9__gnu_cxx18__exchange_and_addEPVii: symbol not found
Error relocating protoc: _ZNSs12_M_leak_hardEv: symbol not found
Error relocating protoc: _ZNSs4swapERSs: symbol not found
Error relocating protoc: _ZNSs6appendERKSs: symbol not found
Error relocating protoc: _ZSt4cerr: symbol not found
Error relocating protoc: _ZTVN10__cxxabiv117__class_type_infoE: symbol not found
Error relocating protoc: _ZSt4cout: symbol not found
Error relocating protoc: _ZTISt9exception: symbol not found
Error relocating protoc: _ZTVN10__cxxabiv120__si_class_type_infoE: symbol not found
Error relocating protoc: _ZTVN10__cxxabiv121__vmi_class_type_infoE: symbol not found
Error relocating protoc: _ZNSs4_Rep20_S_empty_rep_storageE: symbol not found
Error relocating protoc: _ZSt7nothrow: symbol not found
/ # apk --allow-untrusted --no-cache -X http://apkproxy.heroku.com/andyshinn/alpine-pkg-glibc add glibc glibc-bin
fetch http://apkproxy.heroku.com/andyshinn/alpine-pkg-glibc/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
(1/3) Installing glibc (2.23-r3)
(2/3) Installing libgcc (6.2.1-r1)
(3/3) Installing glibc-bin (2.23-r3)
Executing glibc-bin-2.23-r3.trigger
OK: 12 MiB in 18 packages
/ # ./protoc --version
./protoc: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
/ # apk add --no-cache libstdc++
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
(1/1) Installing libstdc++ (6.2.1-r1)
Executing glibc-bin-2.23-r3.trigger
OK: 13 MiB in 19 packages
/ # ./protoc --version
./protoc: /usr/lib/libstdc++.so.6: no version information available (required by ./protoc)
./protoc: /usr/lib/libstdc++.so.6: no version information available (required by ./protoc)
libprotoc 2.6.1

Found it here

Of course it is possible to set custom PB.runProtoc, but then it wouldn't cross-platform.

os72 commented 7 years ago

Thank you. I suppose any Linux binary requiring those shared libs would fail?

BTW Google has started providing protoc binaries for Linux. I guess they fail too, but I'd be curious: java -jar protoc-jar-3.1.0.3.jar -v:com.google.protobuf:protoc:2.6.1 --version

zikolach commented 7 years ago

I suppose so too, but I'd like to see this limitation in Readme. Otherwise "crossplatform" looks kond of misleading ;)

$ docker run -it --rm openjdk:alpine sh
Unable to find image 'openjdk:alpine' locally
alpine: Pulling from library/openjdk
b7f33cc0b48e: Already exists 
43a564ae36a3: Already exists 
b294f0e7874b: Pull complete 
Digest: sha256:21204d8264c0670ae35a18439cd0bf1d91055181fff75aeeb1d1840becfb189c
Status: Downloaded newer image for openjdk:alpine
/ # apk add --no-cache curl && curl -sL http://central.maven.org/maven2/com/github/os72/protoc-jar/3.1.0.3/protoc-jar-3.1.0.3.jar > protoc-jar-3.1.0.3.jar
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
(1/3) Installing libssh2 (1.7.0-r0)
(2/3) Installing libcurl (7.52.1-r0)
(3/3) Installing curl (7.52.1-r0)
Executing busybox-1.24.2-r12.trigger
OK: 141 MiB in 38 packages
/ # java -jar protoc-jar-3.1.0.3.jar -v:com.google.protobuf:protoc:2.6.1 --version
protoc-jar: protoc version: com.google.protobuf:protoc:2.6.1, detected platform: linux/amd64
protoc-jar: downloading: http://central.maven.org/maven2/com/google/protobuf/protoc/2.6.1/protoc-2.6.1-linux-x86_64.exe
protoc-jar: cached: /tmp/protocjar.webcache/com/google/protobuf/protoc/2.6.1/protoc-2.6.1-linux-x86_64.exe
protoc-jar: executing: [/tmp/protocjar2377083706208738892/bin/protoc.exe, --version]
java.io.IOException: Cannot run program "/tmp/protocjar2377083706208738892/bin/protoc.exe": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at com.github.os72.protocjar.Protoc.runProtoc(Protoc.java:88)
    at com.github.os72.protocjar.Protoc.runProtoc(Protoc.java:55)
    at com.github.os72.protocjar.Protoc.main(Protoc.java:37)
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 3 more
/ # 
zikolach commented 7 years ago

BTW Google has started providing protoc binaries for Linux. I guess they fail too.

Exactly

os72 commented 7 years ago

Yes, it's obviously limited cross-platform. And Linux comes in a lot of flavors. But we could keep it as an open issue

golangpkg commented 7 years ago

the alpine have protoc lib but not work. in alpine install like this: apk update && apk add protobuf protobuf-dev but protoc-jar download google protoc lib , so can't run in the alpine .

golangpkg commented 7 years ago

This is not protoc-jar bug . is alpine not have glibc . Look this : only install glibc-2.25-r1.apk well OK . https://github.com/sgerrand/alpine-pkg-glibc

cp sgerrand.rsa.pub  /etc/apk/keys/sgerrand.rsa.pub
/data # apk add glibc-2.25-r1.apk
(1/1) Installing glibc (2.25-r1)
OK: 153 MiB in 39 packages
/data # java -jar protoc-jar-3.1.0.3.jar -v:com.google.protobuf:protoc:2.6.1 --version
protoc-jar: protoc version: com.google.protobuf:protoc:2.6.1, detected platform: linux/amd64
protoc-jar: cached: /tmp/protocjar.webcache/com/google/protobuf/protoc/2.6.1/protoc-2.6.1-linux-x86_64.exe
protoc-jar: executing: [/tmp/protocjar5724818814734029924/bin/protoc.exe, --version]
libprotoc 2.6.1
/data # cat /etc/issue 
Welcome to Alpine Linux 3.4
Kernel \r on an \m (\l)

/data # 
os72 commented 7 years ago

Thanks!

nmost commented 6 years ago

Similar problem on nix. I submitted a patch to scalapb to allow it to just use a custom protoc: https://github.com/scalapb/ScalaPB/pull/367/files#diff-b20ee6b52802a4ee05c85a29da7026c2

Orhideous commented 5 years ago

Faced with same problem.

tiagoapimenta commented 4 years ago

Why not using protobuf statically compiled? It would work regardless of glibc or musl being the libc! Other thing I cannot get is why on the first place it requires to be native, there is no protobuf alternative written in java?

breun commented 3 years ago

Why not using protobuf statically compiled? It would work regardless of glibc or musl being the libc!

I guess that would solve this issue, yes.

Other thing I cannot get is why on the first place it requires to be native, there is no protobuf alternative written in java?

I don't know of a Java implementation, but if you know of one, then sure, that would be perfect.

breun commented 3 years ago

I also ran into the issue of the downloaded protoc not working on Alpine Linux.

@os72 Could protoc-jar add a statically compiled protoc binary for Linux which would work on Linux regardless of the C standard library used by the distribution (glibc/musl)? Or could protoc-jar add an extra protoc binary that dynamically links against musl instead of glibc? (I guess protoc-jar's PlatformDetector would need to be extended to detect the C library in that case.) Or would Google need to add binaries on Maven Central that work on Alpine Linux?

breun commented 3 years ago

I just found that if you install the gcompat package ("The GNU C Library compatibility layer for musl") on Alpine, then the binary from Google does work.

Without gcompat it indeed fails:

% docker run -it --rm alpine
/ # wget https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/3.11.4/protoc-3.11.4-linux-x86_64.exe
Connecting to repo.maven.apache.org (151.101.36.215:443)
saving to 'protoc-3.11.4-linux-x86_64.exe'
protoc-3.11.4-linux- 100% |*******************************************************************************************************************************************| 4972k  0:00:00 ETA
'protoc-3.11.4-linux-x86_64.exe' saved
/ # chmod +x protoc-3.11.4-linux-x86_64.exe
/ # ./protoc-3.11.4-linux-x86_64.exe --version
/bin/sh: ./protoc-3.11.4-linux-x86_64.exe: not found
/ # ldd protoc-3.11.4-linux-x86_64.exe
    /lib64/ld-linux-x86-64.so.2 (0x7fa2f50ac000)
    libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fa2f50ac000)
    libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7fa2f50ac000)
    libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fa2f50ac000)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by protoc-3.11.4-linux-x86_64.exe)
Error relocating protoc-3.11.4-linux-x86_64.exe: __strftime_l: symbol not found

But after adding gcompat it seems to work:

/ # apk add gcompat
(1/3) Installing musl-obstack (1.1-r1)
(2/3) Installing libucontext (1.0-r0)
(3/3) Installing gcompat (1.0.0-r1)
OK: 6 MiB in 17 packages
/ # ./protoc-3.11.4-linux-x86_64.exe --version
libprotoc 3.11.4