pmq20 / ruby-packer

Packing your Ruby application into a single executable.
MIT License
1.56k stars 99 forks source link

Packer own Ruby linking problem - OpenSSL #129

Open zatkowich opened 4 years ago

zatkowich commented 4 years ago

Hi,

I'm trying to use rubyc within Ubuntu 20.04 Docker container and it crashes with following error:

/tmp/rubyc/ruby-2.7.1.dev/revision.h unchanged                                                                                                                                         
linking ruby                                                                                                                                                                           
make[2]: Leaving directory '/tmp/rubyc/build_pass1'                                                                                                                                    
make[1]: Leaving directory '/tmp/rubyc/build_pass1'                                                                                                                                    
make[1]: Entering directory '/tmp/rubyc/build_pass1'                                                                                                                                   
*** Following extensions are not compiled:                                                                                                                                             
openssl:                                                                                                                                                                               
        Could not be configured. It will not be installed.                                                                                                                             
        /tmp/rubyc/ruby-2.7.1.dev/ext/openssl/extconf.rb:97: OpenSSL library could not be found. You might want to use --with-openssl-dir=<dir> option to specify the prefix where Open
SSL is installed.                                                                                                                                                                      
        Check ext/openssl/mkmf.log for more details.                                       
*** Fix the problems, then remove these directories and try again if you want.             
make[1]: Leaving directory '/tmp/rubyc/build_pass1'                                        
-> CI=true ENCLOSE_IO_USE_ORIGINAL_RUBY=true CFLAGS=\ -DRUBY_DEBUG\ -fPIC\ -O3\ -fno-fast-math\ -ggdb3\ -Os\ -fdata-sections\ -ffunction-sections\ -pipe\ \ -I/tmp/rubyc/ruby-2.7.1.dev
\ \ -I/tmp/rubyc/local/include\ \ -I/tmp/rubyc/local/lib/libffi-3.2.1/include\  LDFLAGS=\ -L/tmp/rubyc/local/lib\ \ /tmp/rubyc/local/lib/libz.a\  ENCLOSE_IO_RUBYC_1ST_PASS=true ENCLOS
E_IO_RUBYC_2ND_PASS='' make update-gems      
Downloading bundled gem files...
gems/minitest-5.13.0.gem already exists
gems/net-telnet-0.2.0.gem already exists                                                   
gems/power_assert-1.1.7.gem already exists                                                 
gems/rake-13.0.1.gem already exists                                                        
gems/test-unit-3.3.4.gem already exists                                                    
gems/xmlrpc-0.3.0.gem already exists      
-> CI=true ENCLOSE_IO_USE_ORIGINAL_RUBY=true CFLAGS=\ -DRUBY_DEBUG\ -fPIC\ -O3\ -fno-fast-math\ -ggdb3\ -Os\ -fdata-sections\ -ffunction-sections\ -pipe\ \ -I/tmp/rubyc/ruby-2.7.1.dev
\ \ -I/tmp/rubyc/local/include\ \ -I/tmp/rubyc/local/lib/libffi-3.2.1/include\  LDFLAGS=\ -L/tmp/rubyc/local/lib\ \ /tmp/rubyc/local/lib/libz.a\  ENCLOSE_IO_RUBYC_1ST_PASS=true ENCLOS
E_IO_RUBYC_2ND_PASS='' make extract-gems     
Extracting bundled gem files...
Traceback (most recent call last):
        6: from -e:2:in `<main>'                                                           
        5: from /tmp/rubyc/ruby-2.7.1.dev/tool/gem-unpack.rb:14:in `unpack'
        4: from /tmp/rubyc/ruby-2.7.1.dev/tool/gem-unpack.rb:14:in `open'
        3: from /tmp/rubyc/ruby-2.7.1.dev/tool/gem-unpack.rb:15:in `block in unpack'
        2: from /tmp/rubyc/ruby-2.7.1.dev/lib/rubygems/specification.rb:2426:in `to_ruby'
        1: from /tmp/rubyc/ruby-2.7.1.dev/lib/rubygems/core_ext/kernel_require.rb:92:in `require'
/tmp/rubyc/ruby-2.7.1.dev/lib/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- openssl (LoadError)
make: *** [uncommon.mk:1317: extract-gems] Error 1
Failed running [{"CI"=>"true", "ENCLOSE_IO_USE_ORIGINAL_RUBY"=>"true", "CFLAGS"=>" -DRUBY_DEBUG -fPIC -O3 -fno-fast-math -ggdb3 -Os -fdata-sections -ffunction-sections -pipe  -I/tmp/r
ubyc/ruby-2.7.1.dev  -I/tmp/rubyc/local/include  -I/tmp/rubyc/local/lib/libffi-3.2.1/include ", "LDFLAGS"=>" -L/tmp/rubyc/local/lib  /tmp/rubyc/local/lib/libz.a ", "ENCLOSE_IO_RUBYC_1
ST_PASS"=>"true", "ENCLOSE_IO_RUBYC_2ND_PASS"=>nil}, "make extract-gems"]

It seems that I am unable to set OpenSSL directory to Ruby compilation itself. I'm rather only a bit above being Ruby beginner - so I'm neither able to find which step compiles the Ruby and try adding --with-openssl-dir in there.

pmq20 commented 4 years ago

@zatkowich This is very weird as the GitHub Actions' container can successfully build it. Which rubyc version/binary were you using? Which Ubuntu 20.04 Docker container was it? Could you provide more details/steps so that I can try reproducing it in my local development environment? Thank you very much!

antoinedeschenes commented 4 years ago

I have a similar issue using the a vanilla ubuntu:focal image from docker hub. github actions uses a custom Ubuntu 20.04 virtual machine with a large amount of installed tools, usually not coming from the ubuntu repositories: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md

zatkowich commented 3 years ago

While I didn't have time to deal with this issue either Ubuntu or packer update seems to solve it. Now I'm able to build a binary, however with some additional stuff. Please consider adding the dependencies to documentation.

See an entrypoint script for using rubyc under Ubuntu 20.04 Docker container:

#!/bin/sh

apt update
apt install -y bison build-essential clang curl libssl-dev ruby squashfs-tools

cpan FindBin

rubycPath='/usr/local/bin/rubyc'
rubycUrl='https://gw.alipayobjects.com/os/enclose-prod/1fd23e6b-d48f-4ed0-94dd-f0f539960253/rubyc-v0.4.0-linux-x64.gz'
curl ${rubycUrl} | zcat > ${rubycPath}
chmod +x ${rubycPath}
zatkowich commented 3 years ago

Ok, sorry, this works only for a stable version. If you use the Docker workflow from the previous post with v2.7.1.dev it fails:

#!/bin/sh

apt update
apt install -y bison build-essential clang libssl-dev ruby squashfs-tools wget zlib-dev

cpan FindBin

rubycPath='/usr/local/bin/rubyc'
rubycUrl='https://github.com/pmq20/ruby-packer/releases/download/linux-x64/rubyc'
wget ${rubycUrl}
mv rubyc ${rubycPath}
chmod +x ${rubycPath}

and then try building a project you get the error mentioned in the very first post.

zatkowich commented 3 years ago

I have a solution or better said workaround. Use RVM. It works as it compiles Ruby with OpenSSL support.