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

Update libsass to v3.6.0 and fixes various issues (windows, cross-compilation, binary gems) #96

Merged
merged 3 commits into from May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,5 +12,6 @@
*.so
*.o
*.a
*.gem
mkmf.log
vendor/bundle
2 changes: 1 addition & 1 deletion .gitmodules
@@ -1,3 +1,3 @@
[submodule "ext/libsass"]
path = ext/libsass
url = git://github.com/sass/libsass.git
url = https://github.com/sass/libsass.git
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -6,7 +6,7 @@ This gem combines the speed of `libsass`, the [Sass C implementation](https://gi

### libsass Version

[3.5.2](https://github.com/sass/libsass/releases/tag/3.5.2)
[d225a09a](https://github.com/sass/libsass/commit/d225a09a152050d569c077f97bb944c8dc819d6f)

## Installation

Expand Down
31 changes: 23 additions & 8 deletions Rakefile
@@ -1,15 +1,30 @@
begin
require 'bundler/gem_tasks'
rescue LoadError
puts 'Cannot load bundler/gem_tasks'
end

require 'tasks/libsass'
require 'bundler/gem_tasks'

task default: :test

require 'rake/extensiontask'
gem_spec = Gem::Specification.load("sassc.gemspec")
Rake::ExtensionTask.new('libsass', gem_spec) do |ext|
ext.name = 'libsass'
ext.ext_dir = 'ext'
ext.lib_dir = 'lib/sassc'
ext.cross_compile = true
ext.cross_platform = %w[x86-mingw32 x64-mingw32 x86-linux x86_64-linux]
ext.cross_compiling do |spec|
spec.files.reject! { |path| File.fnmatch?('ext/*', path) }
end
end

desc 'Compile all native gems via rake-compiler-dock (Docker)'
task 'gem:native' do
require 'rake_compiler_dock'
RakeCompilerDock.sh "bundle && gem i rake --no-document && "\
"rake cross native gem MAKE='nice make -j`nproc`' "\
"RUBY_CC_VERSION=2.6.0:2.5.0:2.4.0:2.3.0"
end

desc "Run all tests"
task test: 'libsass:compile' do
task test: 'compile:libsass' do
$LOAD_PATH.unshift('lib', 'test')
Dir.glob('./test/**/*_test.rb') { |f| require f }
end
3 changes: 0 additions & 3 deletions ext/Rakefile

This file was deleted.

36 changes: 36 additions & 0 deletions ext/extconf.rb
@@ -0,0 +1,36 @@
# frozen_string_literal: true

gem_root = File.expand_path('..', __dir__)
libsass_dir = File.join(gem_root, 'ext', 'libsass')

if !File.directory?(libsass_dir) ||
# '.', '..', and possibly '.git' from a failed checkout:
Dir.entries(libsass_dir).size <= 3
Dir.chdir(gem_root) { system('git submodule update --init') } or
fail 'Could not fetch libsass'
end

File.write 'Makefile', <<-MAKEFILE
ifndef DESTDIR
LIBSASS_OUT = #{gem_root}/lib/sassc/libsass.so
else
LIBSASS_OUT = $(DESTDIR)$(PREFIX)/libsass.so
endif

SUB_DIR := #{libsass_dir}
SUB_TARGET := lib/libsass.so

libsass.so:#{' clean' if ENV['CLEAN']}
$(MAKE) -C '$(SUB_DIR)' lib/libsass.so
cp '$(SUB_DIR)/lib/libsass.so' libsass.so
strip libsass.so

install: libsass.so
cp libsass.so '$(LIBSASS_OUT)'

clean:
$(MAKE) -C '$(SUB_DIR)' clean
rm -f '$(LIBSASS_OUT)' libsass.so

.PHONY: clean install
MAKEFILE
2 changes: 1 addition & 1 deletion ext/libsass
Submodule libsass updated 158 files
2 changes: 1 addition & 1 deletion lib/sassc/engine.rb
Expand Up @@ -133,7 +133,7 @@ def output_style

def load_paths
paths = (@options[:load_paths] || []) + SassC.load_paths
paths.join(":") if paths.any?
paths.join(File::PATH_SEPARATOR) unless paths.empty?
end
end
end
8 changes: 7 additions & 1 deletion lib/sassc/native.rb
Expand Up @@ -8,7 +8,13 @@ module Native

spec = Gem.loaded_specs["sassc"]
gem_root = spec.gem_dir
ffi_lib "#{gem_root}/ext/libsass/lib/libsass.so"

ruby_version_so_path = "#{gem_root}/lib/sassc/#{RUBY_VERSION[/\d+.\d+/]}/libsass.so"
if File.exist?(ruby_version_so_path)
ffi_lib ruby_version_so_path
else
ffi_lib "#{gem_root}/lib/sassc/libsass.so"
end

require_relative "native/sass_value"

Expand Down
33 changes: 0 additions & 33 deletions lib/tasks/libsass.rb

This file was deleted.

28 changes: 18 additions & 10 deletions sassc.gemspec
Expand Up @@ -23,26 +23,34 @@ Gem::Specification.new do |spec|

spec.require_paths = ["lib"]

spec.extensions = ["ext/Rakefile"]
spec.platform = Gem::Platform::RUBY
spec.extensions = ["ext/extconf.rb"]

spec.add_development_dependency "minitest", "~> 5.5.1"
spec.add_development_dependency "minitest-around"
spec.add_development_dependency "test_construct"
spec.add_development_dependency "pry"
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
spec.add_development_dependency "rake-compiler"
spec.add_development_dependency "rake-compiler-dock"

spec.add_dependency "rake"
spec.add_dependency "ffi", "~> 1.9"

gem_dir = File.expand_path(File.dirname(__FILE__)) + "/"
`git submodule --quiet foreach pwd`.split($\).each do |submodule_path|
Dir.chdir(submodule_path) do
submodule_relative_path = submodule_path.sub gem_dir, ""
# issue git ls-files in submodule's directory and
# prepend the submodule path to create absolute file paths
`git ls-files`.split($\).each do |filename|
spec.files << "#{submodule_relative_path}/#{filename}"
end

libsass_dir = File.join(gem_dir, 'ext', 'libsass')
if !File.directory?(libsass_dir)
$stderr.puts "Error: ext/libsass not checked out. Please run:\n\n"\
" git submodule update --init"
exit 1
end

Dir.chdir(libsass_dir) do
submodule_relative_path = File.join('ext', 'libsass')
`git ls-files`.split($\).each do |filename|
next if filename =~ %r{(^("?test|docs|script)/)|\.md$|\.yml$}
spec.files << File.join(submodule_relative_path, filename)
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/engine_test.rb
Expand Up @@ -88,7 +88,7 @@ def test_precision_not_specified
SCSS
expected_output = <<-CSS
.foo {
baz: 0.33333; }
baz: 0.3333333333; }
CSS
output = Engine.new(template).render
assert_equal expected_output, output
Expand Down Expand Up @@ -218,7 +218,7 @@ def test_global_load_paths
def test_env_load_paths
expected_load_paths = [ "included_1", "included_2" ]
::SassC.instance_eval { @load_paths = nil }
ENV['SASS_PATH'] = expected_load_paths.join(':')
ENV['SASS_PATH'] = expected_load_paths.join(File::PATH_SEPARATOR)
assert_equal expected_load_paths, ::SassC.load_paths
::SassC.load_paths.clear
end
Expand Down
2 changes: 1 addition & 1 deletion test/native_test.rb
Expand Up @@ -11,7 +11,7 @@ module NativeTest

class General < MiniTest::Test
def test_it_reports_the_libsass_version
assert_equal "3.5.2", Native.version
assert_equal "3.6.0", Native.version
end
end

Expand Down