Skip to content

Instantly share code, notes, and snippets.

@skinnyjames
Last active October 28, 2025 06:40
Show Gist options
  • Select an option

  • Save skinnyjames/55dc075d0d1c12d072b725e96d17a4a7 to your computer and use it in GitHub Desktop.

Select an option

Save skinnyjames/55dc075d0d1c12d072b725e96d17a4a7 to your computer and use it in GitHub Desktop.
proposal gemspec api from mruby
# Proposed DSL API
# Declare a gemspec with an ID
#
# conf contains properties about the build
gemspec "mruby-hokusai-pocket" do |conf|
conf.version = "0.1.0"
conf.author = "skinnyjames"
#..etc
# Declare vanillia C dependency from a github source
#
# (ts) block param contains information about the download
dependency "tree-sitter", github: "tree-sitter/tree-sitter" do |ts|
def build
# run commands as idempotent processes
mkdir(dist_dir)
command("make all install PREFIX=#{dist_dir}", env: env, chdir: ts.dir)
command("make clean", chdir: ts.dir)
conf.libs << File.join(dist_dir, "lib", "libtree-sitter.a")
conf.includes << File.join(dist_dir, "include", "libtree-sitter.h")
end
# ruby helper methods
def env
{
"AR" => conf.ar,
"CC" => conf.gcc,
"PREFIX" => dist_dir
}
end
def dist_dir
File.join(ts.dir, "dist")
end
end
# declare local dependencies from a path
dependency "hokusai-pocket-ast", path: "." do |ast|
# dependencies can declare their own dependencies.
# uses an existing dependency if no params are provided
dependency "tree-sitter"
def build
# some compile command that doesn't yet depend on mruby
command("#{conf.gcc} -L#{conf.libs} -I#{conf.includes} -c somefile.c", chdir: File.join(ast.dir, "src"))
end
end
# when a name is not provided,
# declares a dependency from an existing mgem
#
# note: should be able to override the build
dependency github: "mattn/mruby-onig-regexp" do
def build
# some override here
super
end
end
# test dependencies?
group :test do
dependency github: "skinnyjames/theorem" do
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment