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

Feature: Allow building shared libraries with SONAME #5654

Open
susnux opened this issue Feb 21, 2022 · 1 comment
Open

Feature: Allow building shared libraries with SONAME #5654

susnux opened this issue Feb 21, 2022 · 1 comment

Comments

@susnux
Copy link

susnux commented Feb 21, 2022

For packaging for openSUSE it was needed to add a SONAME to the library, but I think this could be useful for other users as well.
To support versioned SONAME, I had to patch the project like this:

diff -Nur mruby-3.0.0/build_config/host-shared.rb new/build_config/host-shared.rb
--- mruby-3.0.0/build_config/host-shared.rb	2021-03-05 09:07:35.000000000 +0100
+++ new/build_config/host-shared.rb	2022-02-21 12:59:46.926385435 +0100
@@ -18,12 +18,12 @@
 
   conf.archiver do |archiver|
     archiver.command = 'gcc'
-    archiver.archive_options = '-shared -o %{outfile} %{objs}'
+    archiver.archive_options = '-shared -Wl,-soname,%{filename} -o %{outfile} %{objs}'
   end
 
   # file extensions
   conf.exts do |exts|
-     exts.library = '.so'
+     exts.library = '.so.%{version}'
   end
 
   # file separator
diff -Nur mruby-3.0.0/lib/mruby/build/command.rb new/lib/mruby/build/command.rb
--- mruby-3.0.0/lib/mruby/build/command.rb	2021-03-05 09:07:35.000000000 +0100
+++ new/lib/mruby/build/command.rb	2022-02-21 13:10:29.627639126 +0100
@@ -4,7 +4,7 @@
   class Command
     include Rake::DSL
     extend Forwardable
-    def_delegators :@build, :filename, :objfile, :libfile, :exefile
+    def_delegators :@build, :filename, :realname, :objfile, :libfile, :exefile
     attr_accessor :build, :command
 
     def initialize(build)
@@ -234,7 +234,7 @@
     def run(outfile, objfiles)
       mkdir_p File.dirname(outfile)
       _pp "AR", outfile.relative_path
-      _run archive_options, { :outfile => filename(outfile), :objs => filename(objfiles).map{|f| %Q["#{f}"]}.join(' ') }
+      _run archive_options, { :outfile => filename(outfile), :filename => realname(outfile), :objs => filename(objfiles).map{|f| %Q["#{f}"]}.join(' ') }
     end
   end
 
diff -Nur mruby-3.0.0/lib/mruby/build.rb new/lib/mruby/build.rb
--- mruby-3.0.0/lib/mruby/build.rb	2021-03-05 09:07:35.000000000 +0100
+++ new/lib/mruby/build.rb	2022-02-21 12:59:29.906251522 +0100
@@ -6,6 +6,7 @@
   autoload :Gem, "mruby/gem"
   autoload :Lockfile, "mruby/lockfile"
   autoload :Presym, "mruby/presym"
+  autoload :Source, 'mruby/source'
 
   class << self
     def targets
@@ -380,6 +381,10 @@
       end
     end
 
+    def realname(name)
+      filename(name).rpartition(file_separator)[-1]
+    end
+
     def exefile(name)
       if name.is_a?(Array)
         name.flatten.map { |n| exefile(n) }
@@ -403,7 +408,7 @@
       if name.is_a?(Array)
         name.flatten.map { |n| libfile(n) }
       else
-        "#{name}#{exts.library}"
+        "#{name}#{exts.library}" % {:version => MRuby::Source::MRUBY_VERSION}
       end
     end
 
@matz
Copy link
Member

matz commented Feb 22, 2022

Can you make this patch a pull request?

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

2 participants