From 17283484a3666ed279f61dc622a47a133493361d Mon Sep 17 00:00:00 2001 From: Guilherme Carreiro Date: Mon, 7 Oct 2024 23:59:08 +0200 Subject: [PATCH 1/3] Adopt template in spec.files (otherwise, gem consumers can't compile from source) --- erbx.gemspec | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/erbx.gemspec b/erbx.gemspec index 21bdda211..cd77bd2f6 100644 --- a/erbx.gemspec +++ b/erbx.gemspec @@ -13,11 +13,14 @@ Gem::Specification.new do |spec| spec.required_ruby_version = ">= 3.0.0" spec.require_paths = ["lib"] - spec.files = [ - "ext/erbx/extension.c", - "lib/erbx.rb", - # "lib/erbx/version.rb" - ] + + gemspec = File.basename(__FILE__) + spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls| + ls.readlines("\x0", chomp: true).reject do |f| + (f == gemspec) || + f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile]) + end + end spec.extensions = ["ext/erbx/extconf.rb"] spec.metadata["allowed_push_host"] = "https://rubygems.org" From 4429b7578bfc6afa92cf787d1eb16b710f839cc7 Mon Sep 17 00:00:00 2001 From: Guilherme Carreiro Date: Tue, 8 Oct 2024 00:22:30 +0200 Subject: [PATCH 2/3] Update project compilation (use DLEXT instead of SOEXT) --- .gitignore | 4 ++++ Makefile | 4 ++-- Rakefile | 28 +++++++++++----------------- ext/erbx/extconf.rb | 11 ----------- lib/erbx/liberbx.rb | 2 +- 5 files changed, 18 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 0124c1492..5864c4dd1 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ *.so *.so.* *.dylib +*.bundle # Executables *.exe @@ -64,3 +65,6 @@ modules.order Module.symvers Mkfile.old dkms.conf + +# Temporary files +tmp/* diff --git a/Makefile b/Makefile index 2dad3d7f0..3ee73c116 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ test_sources = $(wildcard test/*.c) test_objects = $(test_sources:.c=.o) non_main_objects = $(filter-out src/main.o, $(objects)) -soext ?= $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]') +soext ?= $(shell ruby -e 'puts RbConfig::CONFIG["DLEXT"]') lib_name = lib$(exec).$(soext) ruby_extension = ext/erbx/$(lib_name) @@ -47,4 +47,4 @@ test: $(test_objects) $(non_main_objects) clean: rm -f $(exec) $(test_exec) $(lib_name) $(ruby_extension) - rm -f src/*.o test/*.o + rm -rf src/*.o test/*.o lib/erbx/*.bundle tmp diff --git a/Rakefile b/Rakefile index b8984c84a..e39cf9b4c 100644 --- a/Rakefile +++ b/Rakefile @@ -17,23 +17,17 @@ Rake::TestTask.new(:test) do |t| end Rake::Task[:compile].enhance do - IO.popen("make") do |output| - output.each_line do |line| - puts "#{line}" - end - end + puts "▏compile src/*" - if $?.exitstatus != 0 - raise "src/* could not be compiled #{$?.exitstatus}" - end - end + IO.popen("make") do |output| + output.each_line do |line| + puts "▏#{line}" + end + end - Rake::Task[:clean].enhance do - IO.popen("make clean") do |output| - output.each_line do |line| - puts "#{line}" - end - end - end + if $?.exitstatus != 0 + raise "src/* could not be compiled #{$?.exitstatus}" + end +end - task default: [:compile, :test] \ No newline at end of file +task default: [:compile, :test] diff --git a/ext/erbx/extconf.rb b/ext/erbx/extconf.rb index a7b2ea32a..2d512f9c4 100644 --- a/ext/erbx/extconf.rb +++ b/ext/erbx/extconf.rb @@ -9,16 +9,5 @@ abort "#{extension_name}.h can't be found" end -# expected_functions = [ -# "erbx_lex", -# "erbx_lex_file", -# ] -# -# expected_functions.each do |expected_function| -# unless find_library(extension_name, expected_function) -# abort "lib#{extension_name}.so can't be found or #{expected_function}() not defined in it" -# end -# end - create_header create_makefile("#{extension_name}/#{extension_name}") diff --git a/lib/erbx/liberbx.rb b/lib/erbx/liberbx.rb index 692bf18de..51f330837 100644 --- a/lib/erbx/liberbx.rb +++ b/lib/erbx/liberbx.rb @@ -8,7 +8,7 @@ module LibERBX extend FFI::Library def self.library_extension - RbConfig::CONFIG["SOEXT"] + RbConfig::CONFIG["DLEXT"] end def self.library_name From 0c3d54b5467d11f52d77e53899750368a7407a95 Mon Sep 17 00:00:00 2001 From: Guilherme Carreiro Date: Tue, 8 Oct 2024 00:48:54 +0200 Subject: [PATCH 3/3] Adjust rake tasks --- Rakefile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index e39cf9b4c..d57104dec 100644 --- a/Rakefile +++ b/Rakefile @@ -17,11 +17,9 @@ Rake::TestTask.new(:test) do |t| end Rake::Task[:compile].enhance do - puts "▏compile src/*" - IO.popen("make") do |output| output.each_line do |line| - puts "▏#{line}" + puts "#{line}" end end @@ -30,4 +28,13 @@ Rake::Task[:compile].enhance do end end + +Rake::Task[:clean].enhance do + IO.popen("make clean") do |output| + output.each_line do |line| + puts "#{line}" + end + end +end + task default: [:compile, :test]