Skip to content

Commit 04e96e5

Browse files
committed
Build bundled-gem C extensions before configuring exts
`template/configure-ext.mk.tmpl` discovers bundled-gem C extensions via `Dir.glob(".bundle/gems/**/extconf.rb", base: srcdir)` when `ext/configure-ext.mk` is regenerated. Without an explicit dep, `extract-gems` is not guaranteed to run first, so on a clean tree the glob can return empty and bundled-gem extensions never make it into `exts.mk`. Add `extract-gems` as a prereq of `ext/configure-ext.mk`, gated on `HAVE_BASERUBY` so the cross-compile path is unaffected. Once the bundled-gem ext rules are in `exts.mk`, the existing per-extension Makefile chain (`all: install` -> `install-so install-rb`) produces the `.so`, the `gem.build_complete` marker, and the gemspec copy in `.bundle/specifications/`. Also tidy up the CI setup pipeline: extract `setup/baseruby` and `setup/ubuntu` composite actions and use them from the cross-compile and wasm workflows.
1 parent 30bb824 commit 04e96e5

5 files changed

Lines changed: 117 additions & 39 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Setup directories etc.
2+
description: >-
3+
Build baseruby for cross-compiling
4+
5+
inputs:
6+
srcdir:
7+
required: true
8+
default: ${{ github.workspace }}
9+
description: >-
10+
Directory of source codes.
11+
12+
builddir:
13+
required: false
14+
default: ${{ github.workspace }}/baseruby
15+
description: >-
16+
Where baseruby will be built.
17+
18+
installdir:
19+
required: false
20+
default: install
21+
description: >-
22+
The path where the baseruby will be installed to.
23+
This is relative from the workspace.
24+
25+
outputs:
26+
ruby:
27+
value: ${{ steps.build.outputs.installdir }}/bin/ruby
28+
description: >-
29+
The path of the executable baseruby.
30+
dump_ast:
31+
value: ${{ steps.build.outputs.installdir }}/bin/dump_ast
32+
description: >-
33+
The path of the executable dump_ast.
34+
35+
runs:
36+
using: composite
37+
38+
steps:
39+
- name: Build baseruby
40+
shell: bash
41+
id: build
42+
run: |
43+
case "$installdir" in /*) ;; *) installdir="$PWD/$installdir";; esac
44+
mkdir "$builddir"
45+
ln -sr "$srcdir" "$builddir/.src"
46+
pushd "$builddir"
47+
.src/configure "--prefix=${installdir}" --disable-install-doc
48+
CONFIGURE_ARGS=--with-out-ext=-test- make install
49+
install dump_ast "${installdir}/bin"
50+
{
51+
echo "${installdir}/bin/dump_ast"
52+
echo "${installdir}/.installed.list"
53+
echo "${installdir}/"
54+
} >> .installed.list
55+
cp .installed.list "${installdir}/"
56+
make distclean
57+
rm .src
58+
popd
59+
rmdir "$builddir"
60+
{
61+
echo "installdir=${installdir}"
62+
} | tee -a "$GITHUB_OUTPUT"
63+
env:
64+
srcdir: ${{ inputs.srcdir }}
65+
builddir: ${{ inputs.builddir }}
66+
installdir: ${{ inputs.installdir }}
67+
68+
- name: clean
69+
uses: gacts/run-and-post-run@598d7a875d5620e0457490555b5e18e46082aa47 # v1.4.4
70+
with:
71+
working-directory: ${{ inputs.srcdir }}
72+
post: |
73+
ruby tool/rbuninstall.rb "${{ steps.build.outputs.installdir }}/.installed.list" > /dev/null

.github/actions/setup/ubuntu/action.yml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,45 @@ runs:
2424
using: composite
2525

2626
steps:
27+
- id: uname
28+
name: uname
29+
shell: bash
30+
env:
31+
arch: ${{ inputs.arch }}
32+
run: |
33+
setarch="${arch:+setarch $arch --}"
34+
# normalize `uname`
35+
if uname=$(${setarch} uname -m 2> /dev/null); then
36+
# `setarch` works, `$arch` is a valid architecture name.
37+
echo "setarch=${setarch}" >> "$GITHUB_OUTPUT"
38+
else
39+
# if `setarch` failed, take the given `arch` as-is.
40+
uname="${arch}"
41+
setarch=""
42+
fi
43+
echo "uname=$uname" >> "$GITHUB_OUTPUT"
44+
echo "dpkg=${uname/686/386}" >> "$GITHUB_OUTPUT"
45+
2746
- name: set SETARCH
2847
shell: bash
2948
run: echo "SETARCH=${setarch}" >> "$GITHUB_ENV" # zizmor: ignore[github-env]
3049
env:
31-
setarch: ${{ inputs.arch && format('setarch {0} --', inputs.arch) }}
50+
setarch: ${{ steps.uname.outputs.setarch }} # validated
3251

33-
- id: uname
34-
name: uname
52+
- name: dpkg setup
3553
shell: bash
36-
run: |
37-
echo uname=`${SETARCH} uname -m` >> "$GITHUB_OUTPUT"
38-
echo dpkg=`${SETARCH} uname -m | sed s/686/386/` >> "$GITHUB_OUTPUT"
54+
run: sudo dpkg --add-architecture "${dpkg}"
55+
# `dpkg` is valid, also `uname`.
56+
if: ${{ inputs.arch }}
57+
env:
58+
dpkg: ${{ steps.uname.outputs.dpkg }}
3959

4060
- name: apt-get
4161
shell: bash
4262
env:
4363
arch: ${{ inputs.arch && format(':{0}', steps.uname.outputs.dpkg) || '' }}
4464
run: |
4565
set -x
46-
${arch:+sudo dpkg --add-architecture ${arch#:}}
4766
sudo apt-get update -qq || :
4867
sudo apt-get install --no-install-recommends -qq -y -o=Dpkg::Use-Pty=0 \
4968
${arch:+cross}build-essential${arch/:/-} \

.github/workflows/crosscompile.yml

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ jobs:
6464
builddir: build
6565
makeup: true
6666

67-
- name: Install cross-compilation toolchain
67+
- name: Setup cross-compilation toolchain sources
6868
run: |
69-
sudo dpkg --add-architecture ${{ matrix.arch }}
7069
native_arch=$(dpkg --print-architecture)
7170
# Restrict existing sources to native arch
7271
sudo sed -i '/^Architectures:/d' /etc/apt/sources.list.d/ubuntu.sources
@@ -84,32 +83,25 @@ jobs:
8483
"Components: main universe" \
8584
"Architectures: ${{ matrix.arch }}" \
8685
| sudo tee /etc/apt/sources.list.d/cross-${{ matrix.arch }}.sources
87-
sudo apt-get update -qq
88-
sudo apt-get install --no-install-recommends -qq -y \
89-
crossbuild-essential-${{ matrix.arch }} \
90-
libssl-dev:${{ matrix.arch }} \
91-
libyaml-dev:${{ matrix.arch }} \
92-
zlib1g-dev:${{ matrix.arch }} \
93-
libffi-dev:${{ matrix.arch }} \
94-
libreadline-dev:${{ matrix.arch }} \
95-
libncurses-dev:${{ matrix.arch }} \
96-
autoconf ruby
97-
98-
- name: Build baseruby
99-
run: |
100-
mkdir ../baseruby
101-
cd ../baseruby
102-
../src/configure --prefix=$PWD/install --disable-install-doc
103-
make
104-
make install
86+
87+
- uses: ./.github/actions/setup/ubuntu
88+
with:
89+
arch: ${{ matrix.arch }}
90+
91+
- uses: ./.github/actions/setup/baseruby
92+
id: baseruby
93+
with:
94+
srcdir: src
10595

10696
- name: Run configure
10797
run: >-
10898
../src/configure -C --disable-install-doc
10999
--prefix=/usr
110100
--build=${{ matrix.build }}
111101
--host=${{ matrix.host }}
112-
--with-baseruby=$PWD/../baseruby/install/bin/ruby
102+
--with-baseruby="$baseruby"
103+
env:
104+
baseruby: ${{ steps.baseruby.outputs.ruby }}
113105

114106
- run: make
115107

.github/workflows/wasm.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,10 @@ jobs:
104104
run: |
105105
echo "WASI_SDK_PATH=/opt/wasi-sdk" >> $GITHUB_ENV
106106
107-
- name: Build baseruby
107+
- uses: ./.github/actions/setup/baseruby
108108
id: baseruby
109-
run: |
110-
set -ex
111-
mkdir ../baseruby
112-
pushd ../baseruby
113-
echo "ruby=$PWD/install/bin/ruby" >> $GITHUB_OUTPUT
114-
echo "dump_ast=$PWD/dump_ast" >> $GITHUB_OUTPUT
115-
../src/configure --prefix=$PWD/install
116-
make
117-
make install
109+
with:
110+
srcdir: src
118111

119112
- name: Download config.guess with wasi version
120113
run: |

common.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ $(EXTS_MK): ext/configure-ext.mk $(srcdir)/template/exts.mk.tmpl \
346346
$(srcdir)/template/exts.mk.tmpl --gnumake=$(gnumake) --configure-exts=ext/configure-ext.mk
347347

348348
ext/configure-ext.mk: $(PREP) all-incs $(MKFILES) $(RBCONFIG) $(LIBRUBY) \
349-
$(srcdir)/template/configure-ext.mk.tmpl update-default-gemspecs
349+
$(srcdir)/template/configure-ext.mk.tmpl update-default-gemspecs \
350+
$(HAVE_BASERUBY:yes=extract-gems)
350351
$(ECHO) generating makefiles $@
351352
$(Q)$(MAKEDIRS) $(@D)
352353
$(Q)$(MINIRUBY) $(tooldir)/generic_erb.rb -o $@ -c \

0 commit comments

Comments
 (0)