[前][次][番号順一覧][スレッド一覧]

ruby-changes:73428

From: Takashi <ko1@a...>
Date: Mon, 5 Sep 2022 17:06:54 +0900 (JST)
Subject: [ruby-changes:73428] 06eb9af8c0 (master): Add mjit-bindgen workflow (#6327)

https://git.ruby-lang.org/ruby.git/commit/?id=06eb9af8c0

From 06eb9af8c0d6f415f96a81d4af5c7f8fe3c14ebc Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Mon, 5 Sep 2022 01:06:37 -0700
Subject: Add mjit-bindgen workflow (#6327)

---
 .github/workflows/mjit-bindgen.yml | 101 +++++++++++++++++++++++++++++++++++++
 common.mk                          |  15 ++++++
 tool/mjit/Gemfile                  |   3 +-
 tool/mjit/bindgen.rb               |  54 ++++++++++----------
 4 files changed, 145 insertions(+), 28 deletions(-)
 create mode 100644 .github/workflows/mjit-bindgen.yml

diff --git a/.github/workflows/mjit-bindgen.yml b/.github/workflows/mjit-bindgen.yml
new file mode 100644
index 0000000000..33a1650f92
--- /dev/null
+++ b/.github/workflows/mjit-bindgen.yml
@@ -0,0 +1,101 @@ https://github.com/ruby/ruby/blob/trunk/.github/workflows/mjit-bindgen.yml#L1
+name: MJIT bindgen
+on:
+  push:
+    paths-ignore:
+      - 'doc/**'
+      - '**.md'
+      - '**.rdoc'
+      - '**/.document'
+  pull_request:
+    paths-ignore:
+      - 'doc/**'
+      - '**.md'
+      - '**.rdoc'
+      - '**/.document'
+
+concurrency:
+  group: ${{ github.workflow }} / ${{ startsWith(github.event_name, 'pull') && github.ref_name || github.sha }}
+  cancel-in-progress: ${{ startsWith(github.event_name, 'pull') }}
+
+jobs:
+  make:
+    strategy:
+      matrix:
+        include:
+          - task: mjit-bindgen
+            configure: '--enable-yjit=dev_nodebug'
+          - task: mjit-bindgen
+            arch: i686
+      fail-fast: false
+    env:
+      SETARCH: ${{ matrix.arch && format('setarch {0}', matrix.arch) }}
+    runs-on: ubuntu-20.04
+    if: ${{ !contains(github.event.head_commit.message, '[DOC]') && !contains(github.event.pull_request.labels.*.name, 'Documentation') }}
+    steps:
+      - run: mkdir build
+        working-directory:
+      - name: Set ENV
+        run: |
+          echo "GNUMAKEFLAGS=-j$((1 + $(nproc --all)))" >> $GITHUB_ENV
+      - name: Install libraries
+        env:
+          arch: ${{ matrix.arch }}
+        run: |
+          set -x
+          arch=${arch:+:${arch/i[3-6]86/i386}}
+          ${arch:+sudo dpkg --add-architecture ${arch#:}}
+          sudo apt-get update -q || :
+          sudo apt-get install --no-install-recommends -q -y \
+          ${arch:+cross}build-essential${arch/:/-} \
+          libssl-dev${arch} libyaml-dev${arch} libreadline6-dev${arch} \
+          zlib1g-dev${arch} libncurses5-dev${arch} libffi-dev${arch} \
+          libclang1-10${arch} \
+          bison autoconf ruby
+          sudo apt-get install -q -y pkg-config${arch} || :
+      - name: git config
+        run: |
+          git config --global advice.detachedHead 0
+          git config --global init.defaultBranch garbage
+      - uses: actions/checkout@v3
+        with:
+          path: src
+      - uses: actions/cache@v3
+        with:
+          path: src/.downloaded-cache
+          key: downloaded-cache
+      - name: Fixed world writable dirs
+        run: |
+          chmod -v go-w $HOME $HOME/.config
+          sudo chmod -R go-w /usr/share
+          sudo bash -c 'IFS=:; for d in '"$PATH"'; do chmod -v go-w $d; done' || :
+      - run: ./autogen.sh
+        working-directory: src
+      - name: Run configure
+        env:
+          arch: ${{ matrix.arch }}
+        run: >-
+          $SETARCH ../src/configure -C --disable-install-doc --prefix=$(pwd)/install ${{ matrix.configure }}
+          ${arch:+--target=$arch-$OSTYPE --host=$arch-$OSTYPE}
+      - run: $SETARCH make incs
+      - run: $SETARCH make
+      - run: $SETARCH make install
+      - run: $SETARCH make ${{ matrix.task }}
+      - run: git diff --exit-code
+        working-directory: src
+      - uses: k0kubun/action-slack@v...
+        with:
+          payload: |
+            {
+              "ci": "GitHub Actions",
+              "env": "${{ matrix.os }} / ${{ matrix.test_task }}${{ matrix.configure }}",
+              "url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
+              "commit": "${{ github.sha }}",
+              "branch": "${{ github.ref }}".split('/').reverse()[0]
+            }
+        env:
+          SLACK_WEBHOOK_URL: ${{ secrets.SIMPLER_ALERTS_URL }} # ruby-lang slack: ruby/simpler-alerts-bot
+        if: ${{ failure() && github.event_name == 'push' }}
+
+defaults:
+  run:
+    working-directory: build
diff --git a/common.mk b/common.mk
index ec0ccc5402..0853c5896d 100644
--- a/common.mk
+++ b/common.mk
@@ -229,6 +229,21 @@ yes-mjit-headers: mjit_config.h PHONY https://github.com/ruby/ruby/blob/trunk/common.mk#L229
 mjit.$(OBJEXT): mjit_config.h
 mjit_config.h: Makefile
 
+.PHONY: mjit-bindgen
+mjit-bindgen:
+	$(Q)$(XRUBY) -C $(srcdir) -Ilib \
+		-e 'ENV["GEM_HOME"] = File.expand_path(".bundle")' \
+		-e 'ENV["BUNDLE_APP_CONFIG"] = File.expand_path(".bundle")' \
+		-e 'ENV["BUNDLE_PATH__SYSTEM"] = "true"' \
+		-e 'ENV["BUNDLE_WITHOUT"] = "lint doc"' \
+		-e 'load "spec/bundler/support/bundle.rb"' -- install --gemfile=tool/mjit/Gemfile
+	$(Q)$(XRUBY) -C $(srcdir) -Ilib \
+		-e 'ENV["GEM_HOME"] = File.expand_path(".bundle")' \
+		-e 'ENV["BUNDLE_APP_CONFIG"] = File.expand_path(".bundle")' \
+		-e 'ENV["BUNDLE_GEMFILE"] = "tool/mjit/Gemfile"' \
+		-e 'ENV["BUNDLE_PATH__SYSTEM"] = "true"' \
+		-e 'ENV["BUNDLE_WITHOUT"] = "lint doc"' \
+		-e 'load "spec/bundler/support/bundle.rb"' -- exec tool/mjit/bindgen.rb $(CURDIR)
 
 # These rules using MJIT_HEADER_SUFFIX must be in common.mk, not
 # Makefile.in, in order to override the macro in defs/universal.mk.
diff --git a/tool/mjit/Gemfile b/tool/mjit/Gemfile
index 6a3d0aec81..d7f2838765 100644
--- a/tool/mjit/Gemfile
+++ b/tool/mjit/Gemfile
@@ -1,4 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/tool/mjit/Gemfile#L1
 source 'https://rubygems.org'
 
-gem 'ffi-clang', git: 'https://github.com/ioquatix/ffi-clang'
-gem 'pry-byebug'
+gem 'ffi-clang', git: 'https://github.com/ioquatix/ffi-clang', ref: 'c08ca683c4f4cf73f4dc38539c3180288b360ea1'
diff --git a/tool/mjit/bindgen.rb b/tool/mjit/bindgen.rb
index d2a63581e9..9fded4a985 100755
--- a/tool/mjit/bindgen.rb
+++ b/tool/mjit/bindgen.rb
@@ -4,7 +4,15 @@ require 'etc' https://github.com/ruby/ruby/blob/trunk/tool/mjit/bindgen.rb#L4
 require 'fiddle/import'
 require 'set'
 
-arch_bits = Integer(ARGV.first || 64)
+unless build_dir = ARGV.first
+  abort "Usage: #{$0} BUILD_DIR"
+end
+
+if Fiddle::SIZEOF_VOIDP == 8
+  arch_bits = 64
+else
+  arch_bits = 32
+end
 
 # Help ffi-clang find libclang
 if arch_bits == 64
@@ -235,7 +243,7 @@ class BindingGenerator https://github.com/ruby/ruby/blob/trunk/tool/mjit/bindgen.rb#L243
         in Node[kind: :field_decl, spelling:, bitwidth:, children: [_grandchild]] if bitwidth > 0
           buf << field_builder.call(spelling, "CType::BitField.new(#{bitwidth}, #{node.offsetof.fetch(spelling) % 8})")
         # In most cases, we'd like to let generate_type handle the type unless it's "(unnamed ...)".
-        in Node[kind: :field_decl, spelling:, type:] if !type.empty? && !type.match?(/\(unnamed [^)]+\)\z/)
+        in Node[kind: :field_decl, spelling:, type:] if !type.empty? && !type.match?(/\((unnamed|anonymous) [^)]+\)\z/)
           buf << field_builder.call(spelling, generate_type(type))
         # Lastly, "(unnamed ...)" struct and union are handled here, which are also struct-specific.
         in Node[kind: :field_decl, spelling:, children: [grandchild]]
@@ -312,33 +320,27 @@ class BindingGenerator https://github.com/ruby/ruby/blob/trunk/tool/mjit/bindgen.rb#L320
 end
 
 src_dir = File.expand_path('../..', __dir__)
-if arch_bits == 64
-  build_dir = File.join(src_dir, '.ruby')
-  ruby_platform = RUBY_PLATFORM
-else
-  build_dir = File.join(src_dir, '.ruby-m32')
-  ruby_platform = 'i686-linux'
-end
+build_dir = File.expand_path(build_dir)
 cflags = [
   src_dir,
   build_dir,
   File.join(src_dir, 'include'),
-  File.join(build_dir, ".ext/include/#{ruby_platform}"),
+  File.join(build_dir, ".ext/include/#{RUBY_PLATFORM}"),
 ].map { |dir| "-I#{dir}" }
 
 nodes = HeaderParser.new(File.join(src_dir, 'mjit_compiler.h'), cflags: cflags).parse
 generator = BindingGenerator.new(
   macros: %w[
+    NOT_COMPILED_STACK_SIZE
     USE_LAZY_LOAD
     USE_RVARGC
     VM_CALL_KW_SPLAT
     VM_CALL_TAILCALL
-    NOT_COMPILED_STACK_SIZE
   ],
   enums: {
     rb_method_type_t: %w[
-      VM_METHOD_TYPE_ISEQ
       VM_METHOD_TYPE_CFUNC
+      VM_METHOD_TYPE_ISEQ
     ],
     vm_call_flag_bits: %w[
       VM_CALL_KW_SPLAT_bit
@@ -346,43 +348,43 @@ generator = BindingGenerator.new( https://github.com/ruby/ruby/blob/trunk/tool/mjit/bindgen.rb#L348
     ],
   },
   types: %w[
+    CALL_DATA
     IC
     IVC
     RB_BUILTIN
     VALUE
+    compile_branch
     compile_status
+    inlined_call_context
     iseq_inline_constant_cache
     iseq_inline_constant_cache_entry
     iseq_inline_iv_cache_entry
     iseq_inline_storage_entry
+    mjit_options
     rb_builtin_function
+    rb_call_data
+    rb_callable_method_entry_struct
+    rb_callcache
+    rb_callinfo
     rb_cref_t
     rb_iseq_constant_body
+    rb_iseq_location_t
     rb_iseq_struct
     rb_iseq_t
     rb_iv_index_tbl_entry
-    rb_mjit_compile_info
-    rb_serial_t
-    rb_mjit_unit
-    CALL_DATA
-    rb_call_data
-    rb_callcache
-    rb_callable_method_entry_struct
     rb_method_definition_struct
     rb_method_iseq_t
-    rb_callinfo
     rb_method_type_t
-    mjit_options
-    compile_branch
-    inlined_call_context
-    rb_iseq_location_t
+    rb_mjit_compile_info
+    rb_mjit_unit
+    rb_serial_t
   ],
   ruby_fields: {
     rb_iseq_location_struct: %w[
-      pathobj
       base_label
-      label
       first_lineno
+      label
+      pathobj
     ]
   },
 )
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]