From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 38BAC1F677 for ; Wed, 13 Dec 2023 00:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1702428621; bh=Z0/Bt2sptAroojj3l7GlNB9CC7mZDa5ex4V69svQaws=; h=From:To:Subject:Date:In-Reply-To:References:From; b=K4SvZwmNAXYhiSkveXqiQ8caJ3xNkhxV04UNYAu24LkDjhJl8oTK/MQKi55SWWe2p fiI4hw/4/LsdzkJKGCuugK3y9H1oGkjHf1UX7sngEYkZSOyBY3cOE4NhLROwmQJaRx s6G8Uk0twz/7BxWsEaFMubZ3CzgThjRfbkJPKwPQ= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 08/14] xap_helper_cxx: support clang w/o `c++' executable Date: Wed, 13 Dec 2023 00:50:13 +0000 Message-ID: <20231213005019.26912-9-e@80x24.org> In-Reply-To: <20231213005019.26912-1-e@80x24.org> References: <20231213005019.26912-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This makes the C++ build work on Alpine Linux (tested 3.19.0) without having to install g++ to get the `c++' executable. I've tested this change with and without g++ on Alpine so it'll continue to work if a user decides to install g++. This should continue to work if the Xapian package on Alpine is changed to link against libc++ instead of libstdc++, since we only add `-lstdc++' as a fallback. For reference, Xapian is already linked against libc++ and not libstdc++ on FreeBSD 13.x --- lib/PublicInbox/XapHelperCxx.pm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/XapHelperCxx.pm b/lib/PublicInbox/XapHelperCxx.pm index 8e95ff42..6bd165b8 100644 --- a/lib/PublicInbox/XapHelperCxx.pm +++ b/lib/PublicInbox/XapHelperCxx.pm @@ -7,13 +7,13 @@ # The resulting executable is not linked to Perl in any way. package PublicInbox::XapHelperCxx; use v5.12; -use PublicInbox::Spawn qw(run_die run_qx which); +use PublicInbox::Spawn qw(run_die run_qx run_wait which); use PublicInbox::IO qw(try_cat write_file); use PublicInbox::Search; use Fcntl qw(SEEK_SET); use Config; use autodie; -my $cxx = which($ENV{CXX} // 'c++'); +my $cxx = which($ENV{CXX} // 'c++') // which('clang') // die 'no C++ compiler'; my $dir = substr("$cxx-$Config{archname}", 1); # drop leading '/' $dir =~ tr!/!-!; my $idir = ($ENV{XDG_CACHE_HOME} // @@ -81,7 +81,16 @@ sub build () { my @xflags = split(' ', "$fl $xflags"); # ' ' awk-mode eats leading WS my @cflags = ('-I', $srcpfx, grep(!/\A-(?:Wl|l|L)/, @xflags)); run_die([$cxx, '-o', "$dir/$prog.o", '-c', "$dir/$prog.cpp", @cflags]); - run_die([$cxx, '-o', "$dir/$prog.tmp", "$dir/$prog.o", @xflags]); + + # xapian on Alpine Linux (tested 3.19.0) is linked against libstdc++, + # and clang needs to be told to use it (rather than libc++): + my @try = rindex($cxx, 'clang') >= 0 ? qw(-lstdc++) : (); + my @cmd = ($cxx, '-o', "$dir/$prog.tmp", "$dir/$prog.o", @xflags); + while (run_wait(\@cmd) and @try) { + warn("# attempting to link again with $try[0]...\n"); + push(@cmd, shift(@try)); + } + die "# @cmd failed: \$?=$?" if $?; unlink "$dir/$prog.cpp", "$dir/$prog.o"; write_file '>', "$dir/XFLAGS.tmp", $xflags, "\n"; write_file '>', "$dir/xap_modversion.tmp", $xap_modversion, "\n";