thermite icon indicating copy to clipboard operation
thermite copied to clipboard

Make compiled library name and/or output folder of compiled library configurable

Open malept opened this issue 8 years ago • 2 comments

Mentioned on The Bikeshed (like #42) and expanded upon via Twitter.

malept avatar Nov 27 '17 22:11 malept

In case Twitter goes away or is inaccessible for some folks :)

Thermite copies the dylib to lib/gem_name.native_extension, which doesn't give me room to execute additional Ruby when require "gem_name" happens. This is my lib/gem_name for reference.

require "helix_runtime"
require "rails_fast_attributes/native"
require "rails_fast_attributes/version"
require "active_model"
require "active_model/attribute"
require "active_model/attribute_set"
require "active_model/attribute/user_provided_default"
require "active_record"
require "active_record/relation"
require "active_record/relation/query_attribute"

module RailsFastAttributes
  ORIGINAL_ATTRIBUTE = ActiveModel::Attribute

  class Attribute
    UNINITIALIZED_ORIGINAL_VALUE = Object.new

    def self.inherited(*)
      raise "ActiveModel::Attribute cannot be subclassed when using rails_fast_attributes"
    end

    def self.null(name)
      ORIGINAL_ATTRIBUTE.null(name)
    end

    module UserProvidedDefault
      def self.new(name, value, ty, original_attr = nil)
        Attribute.user_provided_default(name, value, ty, original_attr)
      end
    end
  end

  class AttributeSet
    Builder = RailsFastAttributes::Builder
    YAMLEncoder = ActiveModel::AttributeSet::YAMLEncoder
  end
end

ActiveModel.send(:remove_const, :Attribute)
ActiveModel::Attribute = RailsFastAttributes::Attribute
ActiveModel.send(:remove_const, :AttributeSet)
ActiveModel::AttributeSet = RailsFastAttributes::AttributeSet

sgrif avatar Nov 27 '17 23:11 sgrif

I've created a PR for a custom Ruby extension directory in #49. I'm still uncertain whether I want to allow for a custom library name. Currently the name originates from either lib.name or package.name in Cargo.toml (and then is processed as necessary).

malept avatar Mar 10 '18 02:03 malept