Comments (14)
I was able to resolve this with the following boilerplate at the top of the main file:
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
from ruby-packer.
I was able to make it work. I found several important steps to success:
- Use Gemfile
- Use the same bundler version that
rubyc
wants to use, it was 1.15.3 when I tried. - Maybe use the same ruby version,
rubyc
uses 2.4.0, I had 2.7.0, but the example is simple so it didn't make any difference. - Add at the top of your file
require 'rubygems'
- Add at the top of your file
require 'bundler/setup'
pack/test.rb:
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'colorize'
puts 'one'
puts 'two'.colorize(:red)
pack/Gemfile:
source 'https://rubygems.org'
gem 'colorize'
pack/Gemfile.lock, it was critical that BUNDLED WITH is 1.15.3, that's what rubyc wants.
GEM
remote: https://rubygems.org/
specs:
colorize (0.8.1)
PLATFORMS
ruby
DEPENDENCIES
colorize
BUNDLED WITH
1.15.3
Compiled like
./rubyc --tmpdir=/path/to/tmp --output=test.out --root=./pack ./pack/test.rb
Based on my understanding of the output of rubyc
, it puts ruby (2.4.0) and gems, including bundler (1.15.3), in it's tmp directory and runs bundler with your Gemfile in that environment. It ignores rvm, gemset and what gems installed in there.
from ruby-packer.
Would you happend to remember what arguments you used to compile the package?
From what I understand you should use the same Ruby version as the compiler does. Also, when compiling you should see the dependencies getting fetched from rubygems. So yes, it should do this automatically.
from ruby-packer.
I just did ./rubyc <name-of-file.rb>
I can give it a try by installing ruby 2.4 in my system and re-run, but I have multiple gem dependencies and some of them are modified and sitting on my system. I can push them to a repo but the help argument does not specify how to call multiple gems as dependency and, that to, how to define a source.
from ruby-packer.
I'd suggest you use RVM or rbenv to be able to have multiple ruby versions installed. This way you don't have to worry about the ruby version installed on the system and you can have different projects with different ruby versions.
Personally I like rbenv.
from ruby-packer.
I got rbenv. Now to package an app I just want to know how to declare multiple gems as dependencies?
from ruby-packer.
I see, a Gemfile
with your dependencies should be picked up by the compiler and be put in the package so it can be used by your program.
from ruby-packer.
I'm also experiencing this problem.
test.rb
require 'faker'
puts "Hello #{Faker::Name.name}"
Dockerfile
FROM ruby:2.4.0
RUN apt-get update
RUN apt-get install -y squashfs-tools bison
RUN curl -L http://enclose.io/rubyc/rubyc-linux-x64.gz | gunzip > rubyc
RUN chmod +x rubyc && cp rubyc /usr/local/bin/
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Copy application files
COPY ./app/ ./
RUN rubyc test.rb
docker run -it rubyapp ./a.out
/__enclose_io_memfs__/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- faker (LoadError)
from /__enclose_io_memfs__/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /__enclose_io_memfs__/local/test.rb:1:in `<main>'
from ruby-packer.
maybe add Gemfile and do bundle install ?(now I can not reproduce problem, but I will try do it tomorrow)
from ruby-packer.
Hmm yea i had tried that as well :(
from ruby-packer.
hi, @sk-jlewis yes, the problem is still here. I tried to pack on my host machine, in docker, tried to install gems in the local path with a flag --path=vendor
, tried to modify code of test.rb to set my gem path folder through Gem.use_paths(...)
, tried to require 'rubygems' before 'faker', but anywhere I see the same error:
/__enclose_io_memfs__/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in
require': cannot load such file -- faker (LoadError)`
I found that rubyc
install gems in vendor
path in __enclose_io_memfs__
and even I tried to require an appropriate file from this folder:
require 'vendor/ruby/2.4.0/gems/...'
And I see the error as above. It's like that GEM_PATH or GEM_HOME is not set. And I found that these two env vars set nil before the build. It's only my opinion based on reading sources. Maybe these vars set value anywhere after it.
maybe creators can say what happens(
from ruby-packer.
I'm struggling with the same problem on win10
my test.rb:
require 'rubygems'
require 'bundler/setup'
require 'faker'
puts "Hello #{Faker::Name.name}"
my Gemfile:
source "https://rubygems.org"
gem 'bundler'
gem 'faker'
Nothing I do seems to change gems recognized by rubyc -c test.rb.
I've tried bundle installs, gem installs, the only thing that got me further was static requires to gem paths ie:
require 'C:\Ruby24-x64\lib\ruby\gems\2.4.0\gems\faker-1.9.1\lib\faker.rb'
But since I need eventmachine and serialruby gems I would have to require all of the requirements (and requirement requirements...) as well.
Does someone have a working solution/howto for gems on windows?
from ruby-packer.
@quadur hi, I use rubyc too. did you try to use docker for build your binary file?
ex above #39 (comment)
from ruby-packer.
Problem solved by restarting spring
spring stop
from ruby-packer.
Related Issues (20)
- Pack more files HOT 2
- Can not build with Ruby 3.0.0 HOT 1
- Implicit declaration in C99 error when packing a rails project using Ruby 2.4.10 HOT 3
- Error loading nokogiri when starting compiled binary HOT 14
- The build is broken, due to Rubocop error
- rubyc not starting anymore since enclose.io is down
- Dir.glob returns inconsistent results inside memfs
- Reading from memfs file is not thread safe
- `require` is 10 times slower in packed ruby
- Is it possible to compile for Linux but on a Mac?
- Fails to build with both Stable and Pre-release HOT 1
- [Documentation] Differences to ocra?
- how to install another gems in linux system HOT 1
- TestFailed! nmake /f win32\Makefile.msc Failed running HOT 1
- Error building executable gem: error compiling squash.c
- Provide a GitHub action to setup and run rubyc
- Manual pages not compiled HOT 1
- ruby-packer sets BUNDLE_GEMFILE inside the running script
- Build error HOT 1
- ** Ruby-packer replacement, maintained **
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ruby-packer.