Project

General

Profile

Actions

Bug #19778

closed

mkmf.rb pkg_config() interaction with RbConfig::CONFIG["cflags"]

Added by rhenium (Kazuki Yamaguchi) over 1 year ago. Updated about 1 year ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 3.3.0dev (2023-07-21T09:38:29Z master 22f9735587) [x86_64-linux]
[ruby-core:114250]

Description

(This was first reported at https://github.com/ruby/openssl/issues/650: The extension's build breaks in a strange way if RbConfig::CONFIG["*flags"] contains the path of an OpenSSL installation but pkg-config returns the path of a different OpenSSL installation)

Commit 097c3e9cbbf23718371f08c24b2d2297b039f63f ("mkmf.rb: -I flags to $INCFLAGS", Ruby 2.2) changed how mkmf's pkg_config() handles the result of the pkg-config command. It now stores the -I flags in $INCFLAGS and others in $CFLAGS.

mkmf generates a Makefile that compiles source files with:

$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS)

and link the final library with:

$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)

This "new" behavior of pkg_config() is problematic when RbConfig::CONFIG["{C,CPP}FLAGS"] also provide -I flags and RbConfig::CONFIG["LDFLAGS"] provides the matching -L flags -- for example, if Ruby is compiled with ./configure --with-opt-dir=<dir>. This would end up with compiling sources with

[...] -I<from pkg-config> -I<from RbConfig> [...]

and then linking with

[...] -L<from RbConfig> -L<from pkg-config> [...]

This doesn't seem right. I don't know which should come earlier, but the order should be consistent. The commit in question clearly describes the change in the commit message, but it doesn't have a linked issue. What is it intended for? Also, what is $INCFLAGS?

On the other hand, dir_config() would prepend -I flags to $CPPFLAGS and -L flags to $LIBPATH, so it doesn't have issues with flags from RbConfig, albeit in a differently way.

Updated by mame (Yusuke Endoh) over 1 year ago

  • Assignee set to nobu (Nobuyoshi Nakada)

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN to 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED
Actions #3

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset git|fe0225ff4d5af8b1f54009727b39d0d9b821eea3.


[Bug #19778] Add -I options for opt-dir to $INCFLAGS

These options have been separated from $CFLAGS already in the
other places.

Updated by nagachika (Tomoyuki Chikanaga) about 1 year ago

  • Backport changed from 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED to 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONE

ruby_3_2 5640baa2f82f528a092d92ceaabeb76c43c098ee merged revision(s) fe0225ff4d5af8b1f54009727b39d0d9b821eea3.

Updated by usa (Usaku NAKAMURA) about 1 year ago

  • Backport changed from 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONE to 3.0: REQUIRED, 3.1: DONE, 3.2: DONE

ruby_3_1 8563a144fda2fd130b672541a84d8bad0b6c4cd2 merged revision(s) bcb3247072e6973d0f6b50ca5fed238d5824bd28,fe0225ff4d5af8b1f54009727b39d0d9b821eea3.

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0