Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hi,

My MRuby::Build looks like this:

MRuby::Build.new do |conf| conf.toolchain conf.enable_cxx_exception pdb = "/Fd\"#{ENV['MRUBY_PDB']}\"" conf.cc {|c| c.flags << pdb} conf.cxx {|c| c.flags << pdb} GEMS.each { |g| conf.gem :core => g } DEFINES.each { |d| conf.defines << d } end

How could I modify this to register some additional source files for presym scanning? I don't want them to take part in the build in any way except to add some new symbols. I was expecting something like:

config.presym do |p| p.src_files << "my_src_file" end

Also is it possible to manually inject specific symbols directly into the build from here, without needing to scan source files?

I've messed about for a while but I'm not getting anywhere...

Thank you!

You must be logged in to vote

Replies: 5 comments · 2 replies

Comment options

I too have explored methods for adding supplemental presyms in the period before mruby 3.1.0.
But I remember that it was not possible to do it in the usual way.
If it really is needed, a mechanism probably needs to be added for that.

If you are already writing a gem and using C in it, there is a workaround for now.
Take advantage of the fact that MRB_PRESYM_SCANNING is defined when the mruby build system collects presym from the gem's C source code.

void
mrb_mruby_MYGEM_gem_init(mrb_state *mrb)
{
#ifdef MRB_PRESYM_SCANNING
  MRB_SYM(extra_symbol1);
  MRB_SYM(extra_symbol2);
  mrb_intern_lit(mrb, "$global_variable");
  mrb_intern_lit(mrb, "\x01\x02\x03");
#endif

  ...
}
You must be logged in to vote
0 replies
Comment options

psst!

These are not official practices. They may not be available in the future.

  • (approach 1) Specify a file in the build configuration file that contains an additional presym.

    Interrupt the task with the file task method and intervene with the Binding#local_variable_get method to the local variable ppps.
    The ppps variable is passed to presym.scan.

    presyms = presym.scan(ppps)

    MRuby::Build.new do
      ...
    
      mypresyms = "path/to/extra-presyms.txt"
      presym_path = File.join(self.build_dir, "presym")
      file presym_path => mypresyms do |t|
        e = t.actions[1].binding
        e.local_variable_get(:ppps) << mypresyms
      end
    end

    As for the contents of the extra-presyms.txt file, symbols must be enclosed in <@! " and " !@>.

    <@! "extra_symbol1" !@>
    <@! "extra_symbol2" !@>
    <@! "$global_variable" !@>
    <@! "\x01\x02\x03" !@>
    
  • (approach 2) Interrupt the `presym.scan` method.

    In the block of MRuby::Build.new, presym is still undefined.
    Interrupt MRuby::Build#define_rules to interrupt the scan method of MRuby::Build#presym.

    MRuby::Build.new do
      ...
    
      def self.define_rules
        super
    
        class << self.presym
          def scan(*args)
            presyms = super(*args)
            presyms << "extra_symbol1"
            presyms << "extra_symbol2"
            presyms << "$global_variable"
            presyms << "\x01\x02\x03"
            presyms.uniq!
            presyms.sort_by! { |e| [e.bytesize, e] }
            presyms
          end
        end
      end
    end
You must be logged in to vote
1 reply
@jabamaus
Comment options

Thanks dear blue, you are most helpful and I appreciate it 😃 I am writing an app that embeds mruby not a gem. Strange that this is not officially supported. I would probably go with option 2 in the meantime. Thank you!

Comment options

Is there a reason global variables are not supported in presym? When I add eg $GLOBAL to presym tokens it appears in table.h but not in id.h. I note that globals do not appear in:

SYMBOL_TO_MACRO = {
#      Symbol      =>      Macro
# [prefix, suffix] => [prefix, suffix]
  ["@@"  , ""    ] => ["CV"  , ""    ],
  ["@"   , ""    ] => ["IV"  , ""    ],
  [""    , "!"   ] => [""    , "_B"  ],
  [""    , "?"   ] => [""    , "_Q"  ],
  [""    , "="   ] => [""    , "_E"  ],
  [""    , ""    ] => [""    , ""    ],
}.freeze
You must be logged in to vote
0 replies
Comment options

The reason is that the number of symbols used in the application and the symbols corresponding to global variables is small, so we thought the impact would be small. Another reason is that presym scan and allocation are done during the libmruby build, so it was difficult to apply to symbols in the app.

You must be logged in to vote
1 reply
@jabamaus
Comment options

I'm happily adding my app symbols into presym as per dearblue's suggestion:

MRuby::Build.new do
...

def self.define_rules
super

class << self.presym
  def scan(*args)
    presyms = super(*args)
    presyms << "extra_symbol1"
    presyms << "extra_symbol2"
    presyms << "$global_variable"
    presyms << "\x01\x02\x03"
    presyms.uniq!
    presyms.sort_by! { |e| [e.bytesize, e] }
    presyms
  end
end

end
end

The only problem is that it doesn't work with global variables. It doesn't look hard to, maybe I'll have a go.

I think the above code should be available via something like
conf.presym do |ps|
ps.symbols << "extra_symbol1"
end

As it seems like it is a generally useful thing.

Comment options

Yeah, having the ability to add extra presyms symbols when working with an already built libmruby.a would be ideal.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.