Project

General

Profile

Actions

Misc #19035

closed

Change of have_header behaviour between 3.0 and 3.1 causes problems for C++ extensions

Added by katafrakt (Paweł Świątkowski) 2 months ago. Updated 2 months ago.

Status:
Third Party's Issue
Priority:
Normal
Assignee:
-
[ruby-core:<unknown>]

Description

In 4b6fd8329b46701414aba2eeca10013cf66ec513 the behaviour of have_header changed to actually compile instead of just preprocess (at least that's what I understand). This caused problems in at least one extension using C++ (bindings to RocksDB), which now does not build on MacOS on Ruby 3.1 (while still builds on 3.0.2).

A minimal reproducible code is:

require 'mkmf'
dir_config('rocksdb')
RbConfig::CONFIG["CPP"] = "#{RbConfig::CONFIG['CXX']} -E -std=gnu++17"
have_header('rocksdb/db.h')

This detects a header in 3.0.2, but not in 3.1. Looking at mkmf.log:

DYLD_FALLBACK_LIBRARY_PATH=.:/Users/pawel/.rbenv/versions/3.1.0/lib "clang -I/Users/pawel/.rbenv/versions/3.1.0/include/ruby-3.1.0/x86_64-darwin20 -I/Users/pawel/.rbenv/versions/3.1.0/include/ruby-3.1.0/ruby/backward -I/Users/pawel/.rbenv/versions/3.1.0/include/ruby-3.1.0 -I. -I/Users/pawel/.rbenv/versions/3.1.0/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef  -fno-common -pipe   -c conftest.c"
In file included from conftest.c:3:
/usr/local/include/rocksdb/db.h:14:10: fatal error: 'map' file not found
#include <map>
         ^~~~~
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <rocksdb/db.h>
/* end */

It is because it tries to use clang (i.e. RbConfig::CONFIG['CC']) to compile it, not clang++. I can set RbConfig::CONFIG['CC'] and it works (just generates a bunch of warnings coming from Ruby itself). I'm posting this under Misc, because I don't know if it's a bug or just a hack that stopped working. If the latter, perhaps this change should be documented somewhere, as it is kind of breaking; and I haven't found any notion of it in the changelog of 3.1.

Actions #1

Updated by shyouhei (Shyouhei Urabe) 2 months ago

  • Status changed from Open to Third Party's Issue

I'm sorry that this feature is totally undocumented: there is MakeMakefile["C++"] which uses C++'s toolchain compiler instead of C's.

From 54977cc97f65313ec9f2611c17215aac8c477fa2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@ruby-lang.org>
Date: Mon, 3 Oct 2022 09:46:39 +0900
Subject: [PATCH] use of detected C++ compiler

---
 ext/rocksdb/extconf.rb | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ext/rocksdb/extconf.rb b/ext/rocksdb/extconf.rb
index 50a0d05..4fcae0d 100644
--- a/ext/rocksdb/extconf.rb
+++ b/ext/rocksdb/extconf.rb
@@ -1,4 +1,5 @@
 require "mkmf"
+extend MakeMakefile["C++"]
 
 dir_config('rocksdb')
 RbConfig::CONFIG["CPP"] = "g++ -E -std=gnu++17"
-- 
2.17.1
Actions

Also available in: Atom PDF

Like0
Like0