Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
try cl, g++ and clang++ to build/test C++ libs
  • Loading branch information
FROGGS committed Sep 4, 2015
1 parent 87da75e commit 73a46f6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
21 changes: 12 additions & 9 deletions t/04-nativecall/11-cpp.t
@@ -1,16 +1,19 @@
use v6;
use lib 't/04-nativecall';
use CompileTestLib;
use lib 'lib';
use NativeCall;
use Test;

my $cmd = $*DISTRO.is-win
?? 'cl /LD /EHsc /Fe11-cpp.dll t/04-nativecall/11-cpp.cpp'
!! 'g++ --shared -fPIC -o 11-cpp.so t/04-nativecall/11-cpp.cpp';
my $handle = shell("$cmd 2>&1", :out);
my $output = $handle.out.slurp-rest;
if $handle.out.close.status -> $status {
diag "Error while compiling C++ script:\n$output";
print "1..0 # Skip: Cannot compile C++ script\n";
exit 0
try {
compile_cpp_test_lib('11-cpp');
CATCH {
default {
diag "Error while compiling C++ script:\n$_.payload()";
print "1..0 # Skip: Cannot compile C++ script\n";
exit 0
}
}
}

plan 21;
Expand Down
21 changes: 12 additions & 9 deletions t/04-nativecall/13-cpp-mangling.t
@@ -1,16 +1,19 @@
use v6;
use lib 't/04-nativecall';
use CompileTestLib;
use lib 'lib';
use NativeCall;
use Test;

my $cmd = $*DISTRO.is-win
?? 'cl /LD /EHsc /Fe13-cpp-mangling.dll t/04-nativecall/13-cpp-mangling.cpp'
!! 'g++ --shared -fPIC -o 13-cpp-mangling.so t/04-nativecall/13-cpp-mangling.cpp';
my $handle = shell("$cmd 2>&1", :out);
my $output = $handle.out.slurp-rest;
if $handle.out.close.status -> $status {
diag "Error while compiling C++ script:\n$output";
print "1..0 # Skip: Cannot compile C++ script\n";
exit 0
try {
compile_cpp_test_lib('13-cpp-mangling');
CATCH {
default {
diag "Error while compiling C++ script:\n$_.payload()";
print "1..0 # Skip: Cannot compile C++ script\n";
exit 0
}
}
}

plan 20;
Expand Down
28 changes: 27 additions & 1 deletion t/04-nativecall/CompileTestLib.pm
Expand Up @@ -27,7 +27,33 @@ sub compile_test_lib($name) is export {
shell($l_line);
}
sub compile_cpp_test_lib($name) is export {
my @cmds;
my $VM := $*VM;
my $cfg := $VM.config;
my $so = $VM.name eq 'moar'
?? $cfg<dll>.subst(/^.*\./, '')
!! $cfg<nativecall.so>;
@cleanup = "$name.$so";
if $*DISTRO.is-win {
@cmds = "cl /LD /EHsc /Fe$name.$so t/04-nativecall/$name.cpp",
"g++ --shared -fPIC -o $name.$so t/04-nativecall/$name.cpp",
}
else {
@cmds = "g++ --shared -fPIC -o $name.$so t/04-nativecall/$name.cpp",
"clang++ -stdlib=libc++ --shared -fPIC -o $name.$so t/04-nativecall/$name.cpp",
}
my @fails;
for @cmds -> $cmd {
my $handle = shell("$cmd 2>&1", :out);
my $output = $handle.out.slurp-rest;
@fails.push: "Running '$cmd':\n$output" if $handle.out.close.status;
}
fail @fails.join('=' x 80 ~ "\n") if @fails;
}
END {
# say "cleaning up @cleanup[]";
unlink @cleanup;
#~ unlink @cleanup;
}

0 comments on commit 73a46f6

Please sign in to comment.