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

Failed to install offline on Windows platform #158

Closed
aidistan opened this issue Sep 4, 2019 · 11 comments
Closed

Failed to install offline on Windows platform #158

aidistan opened this issue Sep 4, 2019 · 11 comments
Labels

Comments

@aidistan
Copy link

aidistan commented Sep 4, 2019

Thanks for this great gem!

Recently, I have to install and use this gem offline on Windows platform for some reason. However, I kept getting stuck on this line when building the extension. It seems that Gem::DependencyInstaller always tries to install ffi again although I have installed it offline.


Steps to reproduce this issue on Windows:

  1. Prepare the gem file childprocess-2.0.0.gem (download or build it)
  2. Unplug the network
  3. gem install --local childprocess-2.0.0.gem

Example output:

C:\Workspace>gem install --local childprocess-2.0.0.gem
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
ERROR:  Error installing childprocess-2.0.0.gem:
        ERROR: Failed to build gem native extension.

    current directory: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/childprocess-2.0.0/ext
C:/Ruby25-x64/bin/ruby.exe mkrf_conf.rb

rake failed, exit code 1

Gem files will remain installed in C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/childprocess-2.0.0 for inspection.
Results logged to C:/Ruby25-x64/lib/ruby/gems/2.5.0/extensions/x64-mingw32/2.5.0/childprocess-2.0.0/gem_make.out
@reggieb
Copy link

reggieb commented Sep 5, 2019

We are also getting an error with Windows installations via gemfile. An update of the selenium-webdriver in our Rails app has bumped childprocess from version from 1.0.1 to 2.0.0. This has worked fine for those of the team using Linux and Mac development platforms. But a Windows user now gets this error on running bundle:

Fetching childprocess 2.0.0
Installing childprocess 2.0.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/childprocess-2.0.0/ext
C:/Ruby26-x64/bin/ruby.exe mkrf_conf.rb

rake failed, exit code 1

Gem files will remain installed in
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/childprocess-2.0.0 for inspection.
Results logged to
C:/Ruby26-x64/lib/ruby/gems/2.6.0/extensions/x64-mingw32/2.6.0/childprocess-2.0.0/gem_make.out

An error occurred while installing childprocess (2.0.0), and Bundler cannot
continue.
Make sure that `gem install childprocess -v '2.0.0' --source
'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  webdrivers was resolved to 4.1.2, which depends on
    selenium-webdriver was resolved to 3.142.4, which depends on
      childprocess

@sds
Copy link
Collaborator

sds commented Sep 5, 2019

Hey @aidistan and @reggieb, thanks for the reports.

Can you provide the output of gem_make.out from your respective environments (the Results logged to line)? This could help us better understand what's happening in this case.

Thanks!

@sds sds added the bug label Sep 5, 2019
@reggieb
Copy link

reggieb commented Sep 5, 2019

I'm afraid it's not very helpful:

current directory: C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/childprocess-2.0.0/ext
C:/Ruby26-x64/bin/ruby.exe mkrf_conf.rb

rake failed, exit code 1

@aidistan
Copy link
Author

aidistan commented Sep 5, 2019

Mine is the same as reggieb's.


Here I've tried gem install childprocess -v '2.0.0' --source 'https://rubygems.org/' and succeeded, though gem install --local childprocess-2.0.0.gem without network access still got failed.

@sds
Copy link
Collaborator

sds commented Sep 7, 2019

Hey all, after a quick investigation I don't have a good answer here.

The error is caused by the RubyGems runtime not being able to find a dependency in the local domain

Unable to resolve dependency: user requested 'ffi (~> 1.0, >= 1.0.11)'

I tried modifying the mkrf_conf.rb file to specify the local domain explicitly to see if that resolved it, but we get the same error.

installer_options = {}
installer_options[:domain] = :local
inst = Gem::DependencyInstaller.new(installer_options)

Here are the options we have:

  1. Dig into RubyGems internals to understand if there's a way to get this to work using only locally-installed gems.
  2. Vendor the gems you're installing so you don't need to run gem install in the first place and thus avoid this issue.
  3. Remove this native extension installation workaround entirely and clearly document that Windows users need to explicitly include ffi as a gem dependency in their projects in order to use childprocess.

I'm coming around to 3 given the fact that conditional installation does seem a little bit deceptive. Developers should be able to see clearly what their gems are installing without having to look at custom extensions code.

@DavidS Any thoughts on removing the extension code since you implemented this in #132?

@DavidS
Copy link
Contributor

DavidS commented Sep 9, 2019

The original reason for me having that has vanished, so I have no objections to revert all of that. :(

@aidistan
Copy link
Author

Since Gem::Installer#install always tries to reinstall, I guess a simple way to fix this is to check whether a satisfied version of ffi exists (see PR #159).

sds added a commit that referenced this issue Sep 19, 2019
We originally introduced this logic in #132 without understanding all
the implications.

Issue #158 raised a challenge with this approach.
@sds
Copy link
Collaborator

sds commented Sep 19, 2019

Hey @aidistan, thanks for opening #159.

I still believe the answer here is to remove this logic, and clearly document that Windows users need to explicitly install ffi themselves. This is for the following reasons:

  1. Regardless of platform, you always see a Building native extensions. This could take a while... message when this is not actually the case. ChildProcess is just piggybacking off of the RubyGems extension facilities to conditionally install a gem. This is confusing.
  2. When installing ffi via this workaround, it isn't clear to the user that it is happening. You see the aforementioned Building native extensions message, but aren't told that the ffi gem was installed. Again, this is potentially confusing, but also deceptive in that it hides the dependency.
  3. The workaround requires us to specify a dependency constraint that doesn't respect the constraints defined in the user's own gem dependencies. Users then need to align their dependency constraints with what we've defined in mkrf_conf.rb, duplicating them in their Gemfile/etc. See cannot load such file -- ffi on windows #150 for an example where this confusion occurs.
  4. It introduces a dependency on the rake gem (see Fix #143 - Childprocess v1.0.0 failing to install. #144), unnecessarily coupling us to Rake's release cycle. See Relax rake gem constraint from <=11.x to <=12.x. #147 for an example where we had to cut a new release when Rake issued a new release.

We (specifically, myself) originally merged this in #132 without truly understanding the consequences of that pull request. For this reason and those mentioned above, we're removing this logic in #160.

@aidistan
Copy link
Author

Hey @sds, thanks for the comments and opening #160.

Since we had no further progress under this issue for several days, I opened #159 and left the logic untouched 😄

I completely agree with your first and second points. However, besides the document, I suggest to raise a LoadError when running without ffi gem on Windows platform (refer to this discussion).

@sds
Copy link
Collaborator

sds commented Sep 19, 2019

Thanks for the suggestion. Added a more descriptive error message in c0cc6f2.

sds added a commit that referenced this issue Sep 20, 2019
We originally introduced this logic in #132 without understanding all
the implications.

Issue #158 raised a challenge with this approach.
@sds
Copy link
Collaborator

sds commented Sep 20, 2019

Fixed in #160. Shipped in ChildProcess 3.0.0. Thanks again for the report!

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

No branches or pull requests

4 participants