unit module CompileTestLib; my @cleanup; # files to be cleaned up afterwards sub compile_test_lib($name) is export { my ($c_line, $l_line); my $VM := $*VM; my $cfg := $VM.config; my $libname = $VM.platform-library-name($name.IO); if $VM.name eq 'moar' { my $o = $cfg; # MoarVM exposes exposes GNU make directives here, but we cannot pass this to gcc directly. my $ldshared = $cfg.subst(/'--out-implib,lib$(notdir $@).a'/, "--out-implib,$libname.a"); $c_line = "$cfg -c $cfg $cfg$name$o $cfg t/04-nativecall/$name.c"; $l_line = "$cfg $ldshared $cfg $cfg $cfg$libname $name$o"; @cleanup = << "$libname" "$name$o" >>; } elsif $VM.name eq 'jvm' || $VM.name eq 'js' { $c_line = "$cfg -c $cfg -o$name$cfg $cfg t/04-nativecall/$name.c"; $l_line = "$cfg $cfg $cfg $cfg $cfg$libname $name$cfg"; @cleanup = << $libname "$name$cfg" >>; } else { die "Unknown VM; don't know how to compile test libraries"; } shell($c_line); shell($l_line); } sub compile_cpp_test_lib($name) is export { my @cmds; my $VM := $*VM; my $cfg := $VM.config; my $libname = $VM.platform-library-name($name.IO); @cleanup = $libname; if $*DISTRO.is-win { @cmds = "cl /LD /EHsc /Fe$libname t/04-nativecall/$name.cpp", "g++ --shared -fPIC -o $libname t/04-nativecall/$name.cpp", } else { @cmds = "g++ --shared -fPIC -o $libname t/04-nativecall/$name.cpp", "clang++ -stdlib=libc++ --shared -fPIC -o $libname t/04-nativecall/$name.cpp", } my (@fails, $succeeded); for @cmds -> $cmd { my $proc = shell("$cmd 2>&1", :out); my $output = $proc.out.slurp(:close); if so $proc { $succeeded = 1; last } else { @fails.push: "Running '$cmd':\n$output" } } fail @fails.join('=' x 80 ~ "\n") unless $succeeded; } END { # say "cleaning up @cleanup[]"; unlink @cleanup; } # vim: expandtab shiftwidth=4