Skip to content

Commit cb36fcb

Browse files
authored
Merge pull request #2445 from ruby/fix-vc-compilation-error
Fix error at Ruby CI
2 parents de3a3d7 + ccdef8b commit cb36fcb

File tree

17 files changed

+90
-8
lines changed

17 files changed

+90
-8
lines changed

.github/workflows/ruby.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,31 @@ jobs:
106106
- run: bundle exec rake test:valgrind
107107
env:
108108
RUBY_FREE_AT_EXIT: 1
109+
C99_compile:
110+
runs-on: macos-latest
111+
strategy:
112+
fail-fast: false
113+
matrix:
114+
ruby: ['3.4', head]
115+
steps:
116+
- uses: actions/checkout@v4
117+
- name: Install dependencies
118+
run: |
119+
brew install ruby-build
120+
- uses: ruby/setup-ruby@v1
121+
with:
122+
ruby-version: ${{ matrix.ruby }}
123+
bundler: none
124+
- name: Set working directory as safe
125+
run: git config --global --add safe.directory $(pwd)
126+
- name: Update rubygems & bundler
127+
run: |
128+
ruby -v
129+
gem update --system
130+
- name: clang version
131+
run: clang --version
132+
- name: bin/setup
133+
run: |
134+
bin/setup
135+
- run: bundle exec rake clean compile_c99
136+

Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,11 @@ task :changelog do
437437
puts " (🤑 There is no *unreleased* pull request associated to the milestone.)"
438438
end
439439
end
440+
441+
desc "Compile extension without C23 extensions"
442+
task :compile_c99 do
443+
ENV["TEST_NO_C23"] = "true"
444+
Rake::Task[:"compile"].invoke
445+
ensure
446+
ENV.delete("TEST_NO_C23")
447+
end

ext/rbs_extension/ast_translation.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,4 +1146,6 @@ VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instan
11461146
return ID2SYM(rb_intern3((const char *) constant->start, constant->length, ctx.encoding));
11471147
}
11481148
}
1149+
1150+
rb_raise(rb_eRuntimeError, "Unknown node type: %d", instance->type);
11491151
}

ext/rbs_extension/ast_translation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
#ifndef RBS_EXTENSION_AST_TRANSLATION_H
99
#define RBS_EXTENSION_AST_TRANSLATION_H
1010

11+
#include "compat.h"
12+
13+
SUPPRESS_RUBY_HEADER_DIAGNOSTICS_BEGIN
1114
#include "ruby.h"
1215
#include "ruby/encoding.h"
16+
SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END
1317

1418
#include "rbs/ast.h"
1519
#include "rbs/location.h"

ext/rbs_extension/class_constants.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#ifndef RBS__CONSTANTS_H
99
#define RBS__CONSTANTS_H
1010

11+
#include "compat.h"
12+
13+
SUPPRESS_RUBY_HEADER_DIAGNOSTICS_BEGIN
1114
#include "ruby.h"
15+
SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END
1216

1317
extern VALUE RBS;
1418

ext/rbs_extension/compat.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifdef __clang__
2+
#define SUPPRESS_RUBY_HEADER_DIAGNOSTICS_BEGIN \
3+
_Pragma("clang diagnostic push") \
4+
_Pragma("clang diagnostic ignored \"-Wc2x-extensions\"")
5+
#define SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END \
6+
_Pragma("clang diagnostic pop")
7+
#else
8+
#define SUPPRESS_RUBY_HEADER_DIAGNOSTICS_BEGIN
9+
#define SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END
10+
#endif

ext/rbs_extension/extconf.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@
1313

1414
append_cflags ['-std=gnu99', '-Wimplicit-fallthrough', '-Wunused-result']
1515
append_cflags ['-O0', '-g'] if ENV['DEBUG']
16+
if ENV["TEST_NO_C23"]
17+
puts "Adding -Wc2x-extensions to CFLAGS"
18+
$CFLAGS << " -Werror -Wc2x-extensions"
19+
end
1620

1721
create_makefile 'rbs_extension'

ext/rbs_extension/legacy_location.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#ifndef RBS_LOCATION_H
22
#define RBS_LOCATION_H
33

4+
#include "compat.h"
5+
6+
SUPPRESS_RUBY_HEADER_DIAGNOSTICS_BEGIN
47
#include "ruby.h"
8+
SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END
9+
510
#include "rbs.h"
611

712
/**

ext/rbs_extension/rbs_extension.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#include <stdbool.h>
2+
#include "compat.h"
23

4+
SUPPRESS_RUBY_HEADER_DIAGNOSTICS_BEGIN
35
#include "ruby.h"
46
#include "ruby/re.h"
57
#include "ruby/encoding.h"
8+
SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END
69

710
#include "class_constants.h"
811
#include "rbs.h"

ext/rbs_extension/rbs_string_bridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#ifndef RBS__RBS_STRING_BRIDGING_H
22
#define RBS__RBS_STRING_BRIDGING_H
33

4+
#include "compat.h"
5+
6+
SUPPRESS_RUBY_HEADER_DIAGNOSTICS_BEGIN
47
#include "ruby.h"
58
#include "ruby/encoding.h"
9+
SUPPRESS_RUBY_HEADER_DIAGNOSTICS_END
610

711
#include "rbs/string.h"
812

0 commit comments

Comments
 (0)