Skip to content

Commit 88ac4a0

Browse files
hsbtclaude
andcommitted
Require libfyaml 0.9 and build it from source in CI
The libfyaml-dev package on Ubuntu is 0.8, which segfaults psych's emitter, while 0.9.6 (used on macOS via Homebrew) passes the whole suite. Build the same 0.9.6 release from source in the Linux CI job, and reject libfyaml older than 0.9 in extconf so users get a clear error instead of a runtime crash. Also drop an unused variable in set_canonical. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 23f60da commit 88ac4a0

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

.github/workflows/libfyaml.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,28 @@ jobs:
2626
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
2727
os: [ ubuntu-latest, macos-latest ]
2828

29+
env:
30+
LIBFYAML_VERSION: "0.9.6"
31+
2932
steps:
3033
- uses: actions/checkout@v7.0.0
3134
- name: Set up Ruby and libfyaml
3235
uses: ruby/setup-ruby-pkgs@v1
3336
with:
3437
ruby-version: ${{ matrix.ruby }}
35-
apt-get: "libfyaml-dev pkg-config"
38+
apt-get: "pkg-config"
3639
brew: "libfyaml pkg-config"
40+
- name: Build libfyaml from source
41+
# The libfyaml-dev package on Ubuntu is 0.8, which crashes the emitter,
42+
# so build a known-good release. macOS uses the Homebrew build above.
43+
if: runner.os == 'Linux'
44+
run: |
45+
curl -fsSL "https://github.com/pantoniou/libfyaml/releases/download/v${LIBFYAML_VERSION}/libfyaml-${LIBFYAML_VERSION}.tar.gz" | tar xz
46+
cd "libfyaml-${LIBFYAML_VERSION}"
47+
./configure --prefix=/usr/local
48+
make -j"$(nproc)"
49+
sudo make install
50+
sudo ldconfig
3751
- name: Install dependencies
3852
run: bundle install --jobs 3
3953
- name: Compile with the libfyaml backend

ext/psych/extconf.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
unless pkg_config('libfyaml')
1313
abort "libfyaml was requested with --enable-libfyaml but was not found via pkg-config"
1414
end
15+
# libfyaml 0.8 and earlier crash psych's emitter, so require a known-good
16+
# version rather than building something that segfaults at runtime.
17+
pkgconfig = ENV["PKG_CONFIG"] || "pkg-config"
18+
unless system(pkgconfig, "--atleast-version=0.9", "libfyaml")
19+
abort "The libfyaml backend requires libfyaml 0.9 or newer"
20+
end
1521
$defs << "-DPSYCH_USE_LIBFYAML"
1622

1723
create_makefile 'psych'

ext/psych/psych_emitter_fy.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,6 @@ static VALUE alias(VALUE self, VALUE anchor)
408408

409409
static VALUE set_canonical(VALUE self, VALUE style)
410410
{
411-
psych_fy_emitter_t *e;
412-
TypedData_Get_Struct(self, psych_fy_emitter_t, &psych_emitter_type, e);
413411
/* libfyaml has no canonical emit mode, so reject enabling it rather than
414412
* pretending to honor the request. */
415413
if (RTEST(style)) {

0 commit comments

Comments
 (0)