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

Add weak dependency feature for mrbgems #4129

Closed
wants to merge 4 commits into from

Conversation

dearblue
Copy link
Contributor

This feature is a hint to change the mrbgem inclusion order when specified by spec.add_dependency of mrbgem.rake.
It does not mean that it is depends directly, so it will not include mrbgem by itself.

To use this feature, give the weak: true argument to the MRuby::Gem::Specification#add_dependency method in mruby-XXX/mrbgem.rake.

spec.add_dependency "mruby-sprintf", :weak => true

Example with mruby-print and mruby-sprintf:

  • my_build_config.rb

    configurations = {
      build: {
        host: {
          gems: [
            { core: "mruby-sprintf" },
            { core: "mruby-print" },
          ]
        },
    
        ### So far in the wrong mrbgems order
        host2: {
          gems: [
            { core: "mruby-print" },
            { core: "mruby-sprintf" }
          ]
        },
    
        ### Not including mruby-sprintf
        host3: {
          gems: [
            { core: "mruby-print" }
          ]
        },
    
        host4: {
          gems: [
            { core: "mruby-sprintf" }
          ]
        }
      }
    }
    
    configurations[:build].each do |name, conf|
      MRuby::Build.new(name.to_s) do |c|
        toolchain :gcc
        conf[:gems].each { |*g| gem *g }
      end
    end
  • Build summary of MRUBY_CONFIG=my_build_config.rb ./minirake clean all

    ================================================
          Config Name: host
     Output Directory: build/host
             Binaries: mrbc
        Included Gems:
                 mruby-sprintf - standard Kernel#sprintf method
                 mruby-print - standard print/puts/p
                 mruby-compiler - mruby compiler library
                 mruby-bin-mrbc - mruby compiler executable
    ================================================
    
    ### mruby-sprintf is weak dependency, so included mruby-sprintf before mruby-print
    ================================================
          Config Name: host2
     Output Directory: build/host2
        Included Gems:
                 mruby-sprintf - standard Kernel#sprintf method
                 mruby-print - standard print/puts/p
    ================================================
    
    ### mruby-sprintf is weak dependency, but it is not specified directly, so included mruby-print only
    ================================================
          Config Name: host3
     Output Directory: build/host3
        Included Gems:
                 mruby-print - standard print/puts/p
    ================================================
    
    ================================================
          Config Name: host4
     Output Directory: build/host4
        Included Gems:
                 mruby-sprintf - standard Kernel#sprintf method
    ================================================
    

Compatible problems for users

It is not backwards compatible. Also it will always be treated as dependent for previous mruby versions.

Therefore, it is necessary to decide by require "mruby/source" and MRuby::Source::MRUBY_RELEASE_NO.

e.g.:

# A part of mruby-XXX/mrbgem.rake

require "mruby/source"

spec.add_dependency "mruby-YYY", weak: true if MRuby::Source::MRUBY_RELEASE_NO >= 20000

@dearblue
Copy link
Contributor Author

This pull request will be withdrawn for the following reasons:

  • Ruby allows undefined classes and methods to be written first.
    For example, the Regexp or Complex class, or the sprintf in the printf method.
  • Weak dependency becomes unnecessary by cutting out the dependent part and creating another mrbgem and defining a clear dependency.

@dearblue dearblue closed this Oct 18, 2020
@dearblue dearblue deleted the weak-dependency branch October 18, 2020 11:49
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

Successfully merging this pull request may close these issues.

None yet

1 participant