Skip to content

Commit 0a2bd40

Browse files
committed
[GR-14917] Ensure directory of C files being compiled is first on include path.
PullRequest: truffleruby/767
2 parents c155ca1 + 4a1a78b commit 0a2bd40

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Bug fixes:
1010
* Fixed a race condition when using the interpolate-once (`/o`) modifier in
1111
regular expressions.
1212
* Calling `StringIO#close` multiple times no longer raises an exception (#1640).
13+
* Fixed a bug in include file resolution when compiling C extensions.
1314

1415
New features:
1516

lib/truffle/rbconfig-for-mkmf.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,14 @@
113113
expanded.merge!(common)
114114
mkconfig.merge!(common)
115115

116-
mkconfig['COMPILE_C'] = "ruby #{cext_dir}/preprocess.rb $< | $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG) -xc - -o $@ && #{opt} #{opt_passes} $@ -o $@"
117-
mkconfig['COMPILE_CXX'] = "ruby #{cext_dir}/preprocess.rb $< | $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG) -xc++ - -o $@ && #{opt} #{opt_passes} $@ -o $@"
116+
# We use -I$(<D) (the directory portion of the prerequisite - i.e. the
117+
# C or C++ file) to add the file's path as the first entry on the
118+
# include path. This is to ensure that files from the source file's
119+
# directory are include in preference to others on the include path,
120+
# and is required because we are actually piping the file into the
121+
# compiler which disables this standard behaviour of the C preprocessor.
122+
mkconfig['COMPILE_C'] = "ruby #{cext_dir}/preprocess.rb $< | $(CC) -I$(<D) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG) -xc - -o $@ && #{opt} #{opt_passes} $@ -o $@"
123+
mkconfig['COMPILE_CXX'] = "ruby #{cext_dir}/preprocess.rb $< | $(CXX) -I$(<D) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG) -xc++ - -o $@ && #{opt} #{opt_passes} $@ -o $@"
118124

119125
# From mkmf.rb: "$(CC) #{OUTFLAG}#{CONFTEST}#{$EXEEXT} $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)"
120126
mkconfig['TRY_LINK'] = "#{cc} -o conftest $(INCFLAGS) $(CPPFLAGS) #{base_cflags} #{link_o_files} $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)"

0 commit comments

Comments
 (0)