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

FFI::NotFoundError: Function 'libsass_version' not found when using nix #148

Open
michaelglass opened this issue Aug 28, 2019 · 10 comments
Open

Comments

@michaelglass
Copy link
Contributor

michaelglass commented Aug 28, 2019

Looks like nix won't build the libsass.bundle correctly for some reason. Any ideas?

here's a full backtrace.

$ bundle exec rake graphql:introspection --trace 14:58:39 2019
rake aborted!
FFI::NotFoundError: Function 'libsass_version' not found in [/Users/michaelglass/.gem/ruby/2.5.0/gems/sassc-2.2.0/lib/sassc/libsass.bundle]
/Users/michaelglass/.gem/ruby/2.5.0/gems/ffi-1.11.1/lib/ffi/library.rb:273:in `attach_function'
/Users/michaelglass/.gem/ruby/2.5.0/gems/sassc-2.2.0/lib/sassc/native.rb:37:in `attach_function'
/Users/michaelglass/.gem/ruby/2.5.0/gems/sassc-2.2.0/lib/sassc/native/native_context_api.rb:5:in `<module:Native>'
/Users/michaelglass/.gem/ruby/2.5.0/gems/sassc-2.2.0/lib/sassc/native/native_context_api.rb:4:in `<module:SassC>'
/Users/michaelglass/.gem/ruby/2.5.0/gems/sassc-2.2.0/lib/sassc/native/native_context_api.rb:3:in `<main>'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:83:in `register'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:291:in `block in require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/michaelglass/.gem/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:291:in `require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require_relative'
/Users/michaelglass/.gem/ruby/2.5.0/gems/sassc-2.2.0/lib/sassc/native.rb:58:in `<module:Native>'
/Users/michaelglass/.gem/ruby/2.5.0/gems/sassc-2.2.0/lib/sassc/native.rb:6:in `<module:SassC>'
/Users/michaelglass/.gem/ruby/2.5.0/gems/sassc-2.2.0/lib/sassc/native.rb:5:in `<main>'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:83:in `register'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:291:in `block in require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/michaelglass/.gem/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:291:in `require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require_relative'
/Users/michaelglass/.gem/ruby/2.5.0/gems/sassc-2.2.0/lib/sassc.rb:31:in `<main>'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:83:in `register'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:291:in `block in require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/michaelglass/.gem/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:291:in `require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/sassc-rails-2.1.2/lib/sassc/rails.rb:5:in `<main>'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:83:in `register'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:291:in `block in require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:257:in `load_dependency'
/Users/michaelglass/.gem/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/dependencies.rb:291:in `require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require_relative'
/Users/michaelglass/.gem/ruby/2.5.0/gems/sassc-rails-2.1.2/lib/sassc-rails.rb:3:in `<main>'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:83:in `register'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
/Users/michaelglass/.gem/ruby/2.5.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:81:in `block (2 levels) in require'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:76:in `each'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:76:in `block in require'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:65:in `each'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:65:in `require'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler.rb:114:in `require'
/Users/michaelglass/Documents/work/rails/config/application.rb:12:in `<top (required)>'
/Users/michaelglass/Documents/work/rails/Rakefile:6:in `require'
/Users/michaelglass/Documents/work/rails/Rakefile:6:in `<top (required)>'
/Users/michaelglass/.gem/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_module.rb:29:in `load'
/Users/michaelglass/.gem/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_module.rb:29:in `load_rakefile'
/Users/michaelglass/.gem/ruby/2.5.0/gems/rake-12.3.3/lib/rake/application.rb:703:in `raw_load_rakefile'
/Users/michaelglass/.gem/ruby/2.5.0/gems/rake-12.3.3/lib/rake/application.rb:104:in `block in load_rakefile'
/Users/michaelglass/.gem/ruby/2.5.0/gems/rake-12.3.3/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/michaelglass/.gem/ruby/2.5.0/gems/rake-12.3.3/lib/rake/application.rb:103:in `load_rakefile'
/Users/michaelglass/.gem/ruby/2.5.0/gems/rake-12.3.3/lib/rake/application.rb:82:in `block in run'
/Users/michaelglass/.gem/ruby/2.5.0/gems/rake-12.3.3/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/michaelglass/.gem/ruby/2.5.0/gems/rake-12.3.3/lib/rake/application.rb:80:in `run'
/Users/michaelglass/.gem/ruby/2.5.0/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
/Users/michaelglass/.gem/ruby/2.5.0/bin/rake:23:in `load'
/Users/michaelglass/.gem/ruby/2.5.0/bin/rake:23:in `<top (required)>'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:74:in `load'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:74:in `kernel_load'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:28:in `run'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:424:in `exec'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:27:in `dispatch'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:18:in `start'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.16.2/exe/bundle:30:in `block in <top (required)>'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/nix/store/dlsp4m6g9cz69pbx1a9q27x9fnmyhgxk-ruby-2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.16.2/exe/bundle:22:in `<top (required)>'
/Users/michaelglass/Documents/work/rails/bin/bundle:104:in `load'
/Users/michaelglass/Documents/work/rails/bin/bundle:104:in `<main>'
@lrworth
Copy link

lrworth commented Sep 20, 2019

I have just seen the same thing from bundle exec rails db:migrate, and I'm using nix as well.

@emptyflask
Copy link

Same here, also using nix on MacOS.

/nix/store/qfpfm422812i64v9iwh372w2rk051m34-ruby2.6.3-ffi-1.11.1/lib/ruby/gems/2.6.0/gems/ffi-1.11.1/lib/ffi/library.rb:273:
in `attach_function': Function 'libsass_version' not found in [
  /nix/store/nm1v8gxk2whv6d9f3xp0awma6hii8b88-ruby2.6.3-sassc-2.2.1/lib/ruby/gems/2.6.0/gems/sassc-2.2.1/lib/sassc/libsass.bundle
] (FFI::NotFoundError)

@emptyflask
Copy link

I built the gem manually and compared to the bundle being used by nix, and there's clearly a problem in the compilation step:

 ❯ ls -l /nix/store/46v23jpkv1pvbycbgd3az8ab22kp1x92-ruby2.6.3-sassc-2.2.1/lib/ruby/gems/2.6.0/gems/sassc-2.2.1/lib/sassc/libsass.bundle lib/sassc/libsass.bundle
-r-xr-xr-x 1 jon wheel    4144 Dec 31  1969 /nix/store/46v23jpkv1pvbycbgd3az8ab22kp1x92-ruby2.6.3-sassc-2.2.1/lib/ruby/gems/2.6.0/gems/sassc-2.2.1/lib/sassc/libsass.bundle*
-rwxr-xr-x 1 jon staff 2274992 Sep 23 18:05 lib/sassc/libsass.bundle*

@michaelglass michaelglass changed the title FFI::NotFoundError: Function 'libsass_version' not found FFI::NotFoundError: Function 'libsass_version' not found when using nix Oct 9, 2019
@michaelglass
Copy link
Contributor Author

do other folks have the same issues when using bundix?

@lrworth
Copy link

lrworth commented Oct 23, 2019

I've found the problem: libsass is being compiled with -flto resulting in LLVM bitcode objects which can't be linked with the ld provided by nix's clang. See:

➜  file bind.o
bind.o: LLVM bitcode, wrapper x86_64

If I change ext/extconf.rb like:

-if enable_config('lto', true)
+if enable_config('lto', false)

then we get

➜  file bind.o
bind.o: Mach-O 64-bit object x86_64

and bundle exec rake test passes.

I don't know why this isn't a problem on other platforms.

I don't have time to think about how to solve this properly right now, but hopefully this information helps someone else.

@michaelglass
Copy link
Contributor Author

michaelglass commented Oct 23, 2019

related upstream issue: NixOS/nixpkgs#19098

michaelglass added a commit to michaelglass/sassc-ruby that referenced this issue Oct 23, 2019
emptyflask added a commit to emptyflask/sassc-ruby that referenced this issue Dec 17, 2019
@risicle
Copy link

risicle commented May 12, 2020

Interesting datapoint: attempting to build 2.0.1 with nixpkgs 20.03 through bundix gives me invalid option: --disable-lto

current directory: /nix/store/5m94jgir8n6dyfany3fd2za0ivrlqnz2-ruby2.6.6-sassc-2.0.1/lib/ruby/gems/2.6.0/gems/sassc-2.0.1/ext
/nix/store/1r5m6mlqdkqnyqsx3pcqscj9l7jmrgxa-ruby-2.6.6/bin/ruby -I/nix/store/1r5m6mlqdkqnyqsx3pcqscj9l7jmrgxa-ruby-2.6.6/lib/ruby/2.6.0/rubygems -rrubygems /nix/store/cdl7n07gcfpzfm0j38ycrdqzajqncmsa-ruby2.6.6-rake-13.0.1/lib/ruby/gems/2.6.0/gems/rake-13.0.1/exe/rake RUBYARCHDIR\=/nix/store/5m94jgir8n6dyfany3fd2za0ivrlqnz2-ruby2.6.6-sassc-2.0.1/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-17/2.6.0/sassc-2.0.1 RUBYLIBDIR\=/nix/store/5m94jgir8n6dyfany3fd2za0ivrlqnz2-ruby2.6.6-sassc-2.0.1/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-17/2.6.0/sassc-2.0.1 --disable-lto
invalid option: --disable-lto

@ersinakinci
Copy link

ersinakinci commented Jun 15, 2020

Temporary workaround for those who can't wait for #192 to show up in sassc and whatever packages you're using that depend on it. If you use bundler (not bundix) for gem management, you can run bundle config build.sassc --disable-lto to get the compilation to pass when running bundle install.

@axeltlarsson
Copy link

I had this error too, very grateful for the your workaround with the build flag 🙏 .
I thought I'd chime in and say that if you're using bundix you can pass the flag in buildFlags like so:

rubyEnv = pkgs.bundlerEnv {
  inherit ruby;
  gemfile = ./Gemfile;
  lockfile = ./Gemfile.lock;
  gemset = ./gemset.nix;
  gemConfig = pkgs.defaultGemConfig // {
    sassc = attrs: { buildFlags = [ "--disable-lto" ]; };
  };
};

seasonedfish added a commit to seasonedfish/blog that referenced this issue May 23, 2022
@amiryal
Copy link

amiryal commented Oct 4, 2024

related upstream issue: NixOS/nixpkgs#19098

Thanks for the tip, @michaelglass! In the 5 years since, the upstream issue has been resolved and merged into nixpkgs-unstable; issue gone with a simple nix flake update.

The remaining issue is that, in the currently released gem, LTO is enabled only on Darwin+Nix. I opened #247 to enable LTO by default again on all platforms. Hopefully there will be another release, so we could enjoy LTO e.g. on Linux as well.

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

7 participants