Skip to content

Commit

Permalink
run bundle gem --ext=c
Browse files Browse the repository at this point in the history
  • Loading branch information
hmsk committed Jun 8, 2024
1 parent c6b9982 commit 491e697
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Ruby

on:
push:
branches:
- main

pull_request:

jobs:
build:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby:
- '3.3.1'

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run the default task
run: bundle exec rake
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## [Unreleased]

## [0.1.0] - 2024-05-25

- Initial release
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

source "https://rubygems.org"

# Specify your gem's dependencies in quickjs.gemspec
gemspec

gem "rake", "~> 13.0"

gem "rake-compiler"

gem "test-unit", "~> 3.0"
22 changes: 22 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end

require 'rake/extensiontask'

task build: :compile

GEMSPEC = Gem::Specification.load('quickjs.gemspec')

Rake::ExtensionTask.new('quickjs', GEMSPEC) do |ext|
ext.lib_dir = 'lib/quickjs'
end

task default: %i[clobber compile test]
11 changes: 11 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "quickjs"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require "irb"
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
10 changes: 10 additions & 0 deletions ext/quickjs/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require 'mkmf'

# Makes all symbols private by default to avoid unintended conflict
# with other gems. To explicitly export symbols you can use RUBY_FUNC_EXPORTED
# selectively, or entirely remove this flag.
append_cflags('-fvisibility=hidden')

create_makefile('quickjs/quickjs')
9 changes: 9 additions & 0 deletions ext/quickjs/quickjs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "quickjs.h"

VALUE rb_mQuickjs;

RUBY_FUNC_EXPORTED void
Init_quickjs(void)
{
rb_mQuickjs = rb_define_module("Quickjs");
}
6 changes: 6 additions & 0 deletions ext/quickjs/quickjs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef QUICKJS_H
#define QUICKJS_H 1

#include "ruby.h"

#endif /* QUICKJS_H */
9 changes: 9 additions & 0 deletions lib/quickjs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require_relative "quickjs/version"
require_relative "quickjs/quickjs"

module Quickjs
class Error < StandardError; end
# Your code goes here...
end
5 changes: 5 additions & 0 deletions lib/quickjs/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module Quickjs
VERSION = "0.1.0"
end
30 changes: 30 additions & 0 deletions quickjs.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require_relative 'lib/quickjs/version'

Gem::Specification.new do |spec|
spec.name = 'quickjs'
spec.version = Quickjs::VERSION
spec.authors = ['hmsk']
spec.email = ['[email protected]']

spec.summary = 'Run JavaScript code with QuickJS'
spec.description = 'A native wrapper of QuickJS for Ruby'
spec.homepage = 'https://github.com/hmsk/quickjs.rb'
spec.license = 'MIT'
spec.required_ruby_version = '>= 3.0.0'

spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = spec.homepage
spec.metadata['changelog_uri'] = 'https://github.com/hmsk/quickjs.rb/blob/main/CHANGELOG'

gemspec = File.basename(__FILE__)
spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
ls.readlines("\x0", chomp: true).reject do |f|
(f == gemspec) ||
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
end
end
spec.require_paths = ['lib']
spec.extensions = ['ext/quickjs/extconf.rb']
end
4 changes: 4 additions & 0 deletions sig/quickjs.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Quickjs
VERSION: String
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
end
15 changes: 15 additions & 0 deletions test/quickjs_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "test_helper"

class QuickjsTest < Test::Unit::TestCase
test "VERSION" do
assert do
::Quickjs.const_defined?(:VERSION)
end
end

test "something useful" do
assert_equal("expected", "actual")
end
end
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "quickjs"

require "test-unit"

0 comments on commit 491e697

Please sign in to comment.