From: Eric Wong <e@80x24.org>
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 [thread overview]
Message-ID: <20231213005019.26912-9-e@80x24.org> (raw)
In-Reply-To: <20231213005019.26912-1-e@80x24.org>
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";
next prev parent reply other threads:[~2023-12-13 0:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-13 0:50 [PATCH 00/14] Alpine Linux support Eric Wong
2023-12-13 0:50 ` [PATCH 01/14] t/io: strace is optional on Linux Eric Wong
2023-12-13 0:50 ` [PATCH 02/14] tests: account for missing git-http-backend Eric Wong
2023-12-13 0:50 ` [PATCH 03/14] t/cindex*: skip --join when join(1) is missing Eric Wong
2023-12-13 0:50 ` [PATCH 04/14] tests: attempt compatibility w/ busybox lsof Eric Wong
2023-12-13 0:50 ` [PATCH 05/14] lei inspect: drop unneeded strftime import Eric Wong
2023-12-13 0:50 ` [PATCH 06/14] treewide: avoid strftime %k for portability Eric Wong
2023-12-13 0:50 ` [PATCH 07/14] xap_helper_cxx: decouple from Inline::C Eric Wong
2023-12-13 0:50 ` Eric Wong [this message]
2023-12-13 0:50 ` [PATCH 09/14] install: updates for Alpine Linux and apk Eric Wong
2023-12-13 0:50 ` [PATCH 10/14] test_common: extract oct_is from search.t Eric Wong
2023-12-13 0:50 ` [PATCH 11/14] t/convert-compact: allow S_ISGID bit Eric Wong
2023-12-13 0:50 ` [PATCH 12/14] www_coderepo: fix read buffering Eric Wong
2023-12-13 0:50 ` [PATCH 13/14] gzip_filter: use OO ->zflush dispatch Eric Wong
2023-12-13 0:50 ` [PATCH 14/14] t/lei-import: relax EIO regexp Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231213005019.26912-9-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).