blib/lib/Affix/Build.pm

filter: Statementstmt 23.4% 122 / 520 Branchbran 16.3% 49 / 300 Conditioncond 15.8% 20 / 126 MC/DCmcdc 4.1% 3 / 73 Subroutinesub 42.0% 21 / 50 Podpod 100% 3 / 3 totaltotal 20.3% 218 / 1072 CC 211 SCAR 46.5
CC
211
Cov
20%
_coff_symbols
306.0
_generate_msvc_def
306.0
_build_asm
272.0
CRAP 104.5
« builder/Affix/Builder.pm ↑ Summary blib/lib/Affix/Platform/BSD.pm »
1 56 package Affix::Build v1.4.3 {
2 56 ▶ use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 56 ▶ use experimental qw[class try];
Subroutine BEGIN: called CC=1 SCAR=0.0
4 56 ▶ use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 56 ▶ use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 56 ▶ use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 56 ▶ use Carp qw[croak];
Subroutine BEGIN: called CC=1 SCAR=0.0
8 56 ▶ use Capture::Tiny qw[capture];
Subroutine BEGIN: called CC=1 SCAR=0.0
9 56 ▶ use ExtUtils::MakeMaker;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 56 ▶ use Text::ParseWords;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 56 class Affix::Build {
13  
14 # Public Parameters
15 56 field $os : param : reader //= $^O;
16 56 field $clean : param : reader //= 0;
17 56 field $build_dir : param : reader //= Path::Tiny->tempdir( CLEANUP => $clean );
18 56 field $name : param : reader //= 'affix_lib';
19 56 field $debug : param : reader //= 0;
20 56 field $version : param : reader //= ();
21  
22 # Global flags applied to all compilations of that type
23 # cflags, cxxflags, ldflags, rustflags, etc.
24 56 field $flags : param : reader //= {};
25 56 field $cc : param : reader //= $ENV{AFFIX_CC} // $Config{cc} // 'cc';
26 56 field $cxx : param : reader //= $ENV{AFFIX_CXX} // '';
27  
28 # Internal State
29 56 field @sources;
30 56 field $libname : reader;
31 56 field $linker : reader;
32  
33 # Cached Flag Arrays
34 56 field @cflags;
35 56 field @cxxflags;
36 56 field @ldflags;
37 56 field $_lib;
38 #
39 56 ▶ ADJUST {
Subroutine __ANON__: called CC=22 SCAR=43.2
40 56 ▶ my $so_ext = $Config{so} // 'so';
Condition50%1/2
$Affix::Build::Config{"so"} // "so"
l!l
560
MC/DC0%0/1
$Affix::Build::Config{"so"} // "so"
$Affix::Build::Config{"so"}
Truth table50%1/2
A
A= $Affix::Build::Config{"so"}
Aresult
11
00
41 56 ▶ $build_dir = Path::Tiny->new($build_dir) unless builtin::blessed $build_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($build_dir) 0 56 56
42  
43 # Standard convention: Windows DLLs don't need 'lib' prefix, Unix SOs do.
44 56 ▶ my $prefix = ( $os eq 'MSWin32' || $name =~ /^lib/ ) ? '' : 'lib';
Branch: 1 branch
BranchTrueFalseTotal
$os eq 'MSWin32' || $name =~ /^lib/u ? : 0 56 56
Condition33%1/3
$os eq "MSWin32" or $name =~ /^lib/u
l!l&&r!l&&!r
0056
MC/DC0%0/2
$os eq "MSWin32" or $name =~ /^lib/u
$os eq "MSWin32" $name =~ /^lib/u
Truth table33%1/3
A or B
A= $os eq "MSWin32"B= $name =~ /^lib/u
ABresult
1X1
011
000
45 56 ▶ my $suffix = defined $version ? ".$version" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $version ? : 54 2 56
46 56 my $safe_name = $name;
47 56 $safe_name =~ s/[^\w.-]/_/g;
48 56 $libname = $build_dir->child("$prefix$safe_name.$so_ext$suffix")->absolute;
49  
50 # A C++ driver override defaults to the C++ sibling of the C compiler.
51 56 ▶ $cxx ||= $self->_is_msvc($cc) ? $cc : $cc =~ /clang/i ? 'clang++' : $cc =~ /gcc/ ? 'g++' : 'c++';
Branch: 3 branches
BranchTrueFalseTotal
$self->_is_msvc($cc) ? : 0 56 56
$cc =~ /clang/iu ? : 0 56 56
$cc =~ /gcc/u ? : 0 56 56
Condition33%1/3
$cxx ||= $self->_is_msvc($cc) ? $cc : ($cc =~ /clang/iu ? "clang++" : ($cc =~ /gcc/u ? "g++" : "c++"))
l!l&&r!l&&!r
0560
MC/DC0%0/2
$cxx ||= $self->_is_msvc($cc) ? $cc : ($cc =~ /clang/iu ? "clang++" : ($cc =~ /gcc/u ? "g++" : "c++"))
$cxx $self->_is_msvc($cc) ? $cc : ($cc =~ /clang/iu ? "clang++" : ($cc =~ /gcc/u ? "g++" : "c++"))
Truth table33%1/3
A ||= B
A= $cxxB= $self->_is_msvc($cc) ? $cc : ($cc =~ /clang/iu ? "clang++" : ($cc =~ /gcc/u ? "g++" : "c++"))
ABresult
1X1
011
000
52  
53 # We prefer C++ drivers (g++, clang++) to handle standard libraries for mixed code (C+Rust, C+C++)
54 56 ▶ $linker = $self->_is_msvc($cc) ? ( $self->_can_run(qw[cl link]) // $cc // 'cl' ) :
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_msvc($cc) ? : 0 56 56
Condition20%2/10
($self->_can_run("cl", "link") // $cc) // "cl"
l!l
00
$self->_can_run("cl", "link") // $cc
l!l&&r!l&&!r
000
$self->_can_run("g++", "clang++", "c++", "icpx") or $self->_can_run("cc", "gcc", "clang", "icx", "cl") or "c++"
l!l
560
$self->_can_run("g++", "clang++", "c++", "icpx") or $self->_can_run("cc", "gcc", "clang", "icx", "cl")
l!l&&r!l&&!r
5600
MC/DC0%0/2
($self->_can_run("cl", "link") // $cc) // "cl"
$self->_can_run("cl", "link") $cc
MC/DC0%0/2
$self->_can_run("g++", "clang++", "c++", "icpx") or $self->_can_run("cc", "gcc", "clang", "icx", "cl") or "c++"
$self->_can_run("g++", "clang++", "c++", "icpx") $self->_can_run("cc", "gcc", "clang", "icx", "cl")
Truth table0%0/3
A // B
A= $self->_can_run("cl", "link")B= $cc
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $self->_can_run("g++", "clang++", "c++", "icpx")B= $self->_can_run("cc", "gcc", "clang", "icx", "cl")
ABresult
1X1
011
000
55 ( $self->_can_run(qw[g++ clang++ c++ icpx]) || $self->_can_run(qw[cc gcc clang icx cl]) || 'c++' );
56  
57 # Parse global flags...
58 56 ▶ my $keep = $^O eq 'MSWin32' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 56 56
59 56 ▶ @cflags = map { chomp; $_ } grep { defined && length } Text::ParseWords::parse_line( q/ /, $keep, $flags->{cflags} // '' );
Condition80%4/5
defined $_ && length $_
!ll&&!rl&&r
05870
$flags->{"cflags"} // ""
l!l
542
MC/DC50%1/2
defined $_ && length $_
defined $_ length $_
MC/DC100%1/1
$flags->{"cflags"} // ""
$flags->{"cflags"}
Truth table66%2/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
Truth table100%2/2
A
A= $flags->{"cflags"}
Aresult
11
00
60 0 ▶ @cxxflags = map { chomp; $_ } grep { defined && length } Text::ParseWords::parse_line( q/ /, $keep, $flags->{cxxflags} // '' );
Condition20%1/5
defined $_ && length $_
!ll&&!rl&&r
000
$flags->{"cxxflags"} // ""
l!l
056
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
MC/DC0%0/1
$flags->{"cxxflags"} // ""
$flags->{"cxxflags"}
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
Truth table50%1/2
A
A= $flags->{"cxxflags"}
Aresult
11
00
61 0 ▶ @ldflags = map { chomp; $_ } grep { defined && length } Text::ParseWords::parse_line( q/ /, $keep, $flags->{ldflags} // '' );
Condition40%2/5
defined $_ && length $_
!ll&&!rl&&r
000
$flags->{"ldflags"} // ""
l!l
254
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
MC/DC100%1/1
$flags->{"ldflags"} // ""
$flags->{"ldflags"}
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
Truth table100%2/2
A
A= $flags->{"ldflags"}
Aresult
11
00
62 }
63  
64 56 ▶ method add ( $input, %args ) {
Subroutine add: called CC=8 SCAR=21.4
Pod documented
65 56 $_lib = (); # Reset cached library handle
66 56 my ( $path, $lang );
67 56 ▶ if ( ref $input eq 'SCALAR' ) { # Inline source code
Branch: 1 branch
BranchTrueFalseTotal
if (ref $input eq 'SCALAR') { } 2 54 56
68 2 ▶ $args{lang} // croak q[Parameter 'lang' (extension) is required for inline source];
Condition50%1/2
$args{"lang"} // croak("Parameter 'lang' (extension) is required for inline source")
l!l
20
MC/DC0%0/1
$args{"lang"} // croak("Parameter 'lang' (extension) is required for inline source")
$args{"lang"}
Truth table50%1/2
A
A= $args{"lang"}
Aresult
11
00
69 2 $lang = lc $args{lang};
70 2 ▶ croak "Invalid language '$lang'" unless $lang =~ /^[a-z0-9+#]+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $lang =~ /^[a-z0-9+#]+$/u 0 2 2
71  
72 # Generate a unique filename in the build dir
73 2 state $counter = 0;
74 2 my $fname = sprintf( "source_%03d.%s", ++$counter, $lang );
75 2 $path = $build_dir->child($fname);
76 2 $path->spew_utf8($$input);
77 }
78 else { # File path
79 54 $path = Path::Tiny::path($input)->absolute;
80 54 ▶ croak "File not found: $path" unless $path->exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $path->exists 0 54 54
81 54 ($lang) = $path =~ /\.([^.]+)$/;
82 54 ▶ $lang = lc( $lang // '' );
Condition50%1/2
$lang // ""
l!l
540
MC/DC0%0/1
$lang // ""
$lang
Truth table50%1/2
A
A= $lang
Aresult
11
00
83 }
84  
85 # Handle local flags
86 56 ▶ my $local_flags = $args{flags} // [];
Condition50%1/2
$args{"flags"} // []
l!l
056
MC/DC0%0/1
$args{"flags"} // []
$args{"flags"}
Truth table50%1/2
A
A= $args{"flags"}
Aresult
11
00
87 56 ▶ $local_flags = [ split ' ', $local_flags ] unless builtin::reftype $local_flags eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::reftype($local_flags) eq "ARRAY" 0 56 56
88 56 push @sources, { path => $path, lang => $lang, flags => $local_flags };
89 }
90  
91 56 ▶ method compile_and_link () {
Subroutine compile_and_link: called CC=3 SCAR=11.8
Pod documented
92 56 ▶ croak "No sources added" unless @sources;
Branch: 1 branch
BranchTrueFalseTotal
unless @sources 0 56 56
93  
94 # Check if we are mixing languages
95 56 my %langs = map { $_->{lang} => 1 } @sources;
96 56 ▶ if ( ( scalar keys %langs ) > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %langs > 1) 0 56 56
97 0 return $self->_strategy_polyglot();
98 }
99 56 return $_lib = $self->_strategy_native();
100 }
101 218 ▶ method link { $_lib //= $self->compile_and_link(); $_lib }
Subroutine link: called CC=2 SCAR=7.1
Pod documented
Condition66%2/3
$_lib //= $self->compile_and_link
l!l&&r!l&&!r
163550
MC/DC0%0/2
$_lib //= $self->compile_and_link
$_lib $self->compile_and_link
Truth table66%2/3
A //= B
A= $_libB= $self->compile_and_link
ABresult
1X1
011
000
102  
103 # Used when only one language is present. We delegate the entire build process
104 # to that language's compiler to produce the final shared library.
105 56 ▶ method _strategy_native () {
Subroutine _strategy_native: called CC=1 SCAR=0.0
106 56 my $src = $sources[0];
107 56 my $l = $src->{lang};
108 56 my $handler = $self->_resolve_handler($l);
109 56 return $self->$handler( $src, $libname, 'dynamic' );
110 }
111  
112 # Parse COFF object files (.obj, .o) directly to extract defined external symbols
113 0 ▶ method _coff_symbols ($path) {
Subroutine _coff_symbols: not called CC=17 SCAR=57.2
114 0 ▶ open my $fh, '<:raw', "$path" or return ();
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", "$path" or return () 0 0 0
115 0 my $header;
116 0 ▶ return () unless read( $fh, $header, 20 ) == 20;
Branch: 1 branch
BranchTrueFalseTotal
unless read($fh, $header, 20) == 20 0 0 0
117 0 my ( $machine, $num_sections, $timedate, $sym_ptr, $num_syms, $opt_hdr_sz, $flags ) = unpack( 'v v V V V v v', $header );
118 0 ▶ return () unless $sym_ptr && $num_syms;
Branch: 1 branch
BranchTrueFalseTotal
unless $sym_ptr and $num_syms 0 0 0
Condition0%0/3
$sym_ptr and $num_syms
!ll&&!rl&&r
000
MC/DC0%0/2
$sym_ptr and $num_syms
$sym_ptr $num_syms
Truth table0%0/3
A and B
A= $sym_ptrB= $num_syms
ABresult
0X0
100
111
119 0 ▶ seek( $fh, $sym_ptr, 0 ) or return ();
Branch: 1 branch
BranchTrueFalseTotal
seek $fh, $sym_ptr, 0 or return () 0 0 0
120 0 my $str_ptr = $sym_ptr + $num_syms * 18;
121 0 my @syms;
122 0 my $i = 0;
123  
124 0 ▶ while ( $i < $num_syms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num_syms) 0 0 0
125 0 my $entry;
126 0 ▶ last unless read( $fh, $entry, 18 ) == 18;
Branch: 1 branch
BranchTrueFalseTotal
unless read($fh, $entry, 18) == 18 0 0 0
127 0 $i++;
128 0 my ( $short_name, $val, $sect_num, $type, $storage_class, $num_aux ) = unpack( 'a8 V s v C C', $entry );
129 0 ▶ if ( $storage_class == 2 && $sect_num > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($storage_class == 2 and $sect_num > 0) 0 0 0
Condition0%0/3
$storage_class == 2 and $sect_num > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$storage_class == 2 and $sect_num > 0
$storage_class == 2 $sect_num > 0
Truth table0%0/3
A and B
A= $storage_class == 2B= $sect_num > 0
ABresult
0X0
100
111
130 0 my $name;
131 0 my ( $zeroes, $offset ) = unpack( 'V V', $short_name );
132 0 ▶ if ( $zeroes == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zeroes == 0) { } 0 0 0
133 0 my $cur = tell($fh);
134 0 ▶ if ( seek( $fh, $str_ptr + $offset, 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (seek $fh, $str_ptr + $offset, 0) 0 0 0
135 0 my $str = '';
136 0 my $char;
137 0 ▶ while ( read( $fh, $char, 1 ) && $char ne "\0" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, $char, 1 and $char ne "\0") 0 0 0
Condition0%0/3
read $fh, $char, 1 and $char ne "\0"
!ll&&!rl&&r
000
MC/DC0%0/2
read $fh, $char, 1 and $char ne "\0"
read $fh, $char, 1 $char ne "\0"
Truth table0%0/3
A and B
A= read $fh, $char, 1B= $char ne "\0"
ABresult
0X0
100
111
138 0 $str .= $char;
139 }
140 0 $name = $str;
141 }
142 0 seek( $fh, $cur, 0 );
143 }
144 else {
145 0 $name = $short_name;
146 0 $name =~ s/\0+$//;
147 }
148 0 ▶ push @syms, $name if defined $name && length $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name and length $name 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
149 }
150 0 ▶ if ( $num_aux > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num_aux > 0) 0 0 0
151 0 seek( $fh, $num_aux * 18, 1 );
152 0 $i += $num_aux;
153 }
154 }
155 0 close $fh;
156 0 return @syms;
157 }
158  
159 # Generate a module-definition (.def) file to export all symbols on MSVC
160 0 ▶ method _generate_msvc_def ( $def_file, @files ) {
Subroutine _generate_msvc_def: not called CC=17 SCAR=57.2
161 0 my %symbols;
162 0 my $dumpbin = $self->_can_run('dumpbin');
163 0 ▶ if ( !$dumpbin && $cc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $dumpbin and $cc) 0 0 0
Condition0%0/3
not $dumpbin and $cc
!ll&&!rl&&r
000
MC/DC0%0/2
not $dumpbin and $cc
not $dumpbin $cc
Truth table0%0/3
not(A) and B
A= not $dumpbinB= $cc
ABresult
0X0
100
111
164 0 my $p = Path::Tiny::path($cc)->parent->child('dumpbin.exe');
165 0 ▶ $dumpbin = "$p" if -x "$p";
Branch: 1 branch
BranchTrueFalseTotal
if -x "$p" 0 0 0
166 }
167 0 for my $f (@files) {
168 0 ▶ next unless -e "$f";
Branch: 1 branch
BranchTrueFalseTotal
unless -e "$f" 0 0 0
169 0 my @raw;
170 0 ▶ if ($dumpbin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dumpbin) 0 0 0
171 0 ▶ my ($out) = capture { system $dumpbin, '/SYMBOLS', "$f" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
172 0 for my $line ( split /\r?\n/, $out ) {
173 0 ▶ if ( $line =~ /SECT\S*.*?\bExternal\b\s*\|\s*(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /SECT\S*.*?\bExternal\b\s*\|\s*(\S+)/u) 0 0 0
174 0 push @raw, $1;
175 }
176 }
177 }
178 0 ▶ if ( !@raw ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@raw) 0 0 0
179 0 push @raw, $self->_coff_symbols("$f");
180 }
181 0 for my $sym (@raw) {
182 0 ▶ next if $sym =~ /^[?.]/;
Branch: 1 branch
BranchTrueFalseTotal
if $sym =~ /^[?.]/u 0 0 0
183 0 ▶ next if $sym =~ /^__(?:real|x86|local_stdio)/;
Branch: 1 branch
BranchTrueFalseTotal
if $sym =~ /^__(?:real|x86|local_stdio)/u 0 0 0
184 0 ▶ next if $sym =~ /^_RTC_/;
Branch: 1 branch
BranchTrueFalseTotal
if $sym =~ /^_RTC_/u 0 0 0
185 0 ▶ next if $sym =~ /^(?:_fltused|DllMain|_DllMainCRTStartup|DllMainCRTStartup)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $sym =~ /^(?:_fltused|DllMain|_DllMainCRTStartup|DllMainCRTStartup)$/u 0 0 0
186 0 ▶ $sym =~ s/^_// if $Config{ptrsize} == 4;
Branch: 1 branch
BranchTrueFalseTotal
if $Affix::Build::Config{"ptrsize"} == 4 0 0 0
187 0 $symbols{$sym} = 1;
188 }
189 }
190 0 ▶ if ( keys %symbols ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %symbols) 0 0 0
191 0 my $content = "EXPORTS\n" . join( "\n", map {" $_"} sort keys %symbols ) . "\n";
192 0 $def_file->spew_utf8($content);
193 0 return $def_file;
194 }
195 0 return undef;
196 }
197  
198 # Used when mixing languages (e.g. C + Rust). We compile everything to
199 # static artifacts (.o or .a) and then use the system linker to combine them.
200 0 ▶ method _strategy_polyglot () {
Subroutine _strategy_polyglot: not called CC=15 SCAR=54.8
201 0 my ( @files, @libs );
202 0 foreach my $src (@sources) {
203 0 my $handler = $self->_resolve_handler( $src->{lang} );
204  
205 # Request 'static' output from the handler
206 0 my $res = $self->$handler( $src, undef, 'static' );
207 0 push @files, $res->{file};
208 0 ▶ push @libs, @{ $res->{libs} } if $res->{libs};
Branch: 1 branch
BranchTrueFalseTotal
if $res->{"libs"} 0 0 0
209 }
210  
211 # Link step
212 0 my $msvc = $self->_is_msvc;
213 0 my @cmd = ($linker);
214 0 ▶ if ($msvc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msvc) { } 0 0 0
215 0 push @cmd, '/nologo', '/LD';
216 0 my $def = $build_dir->child( $self->_base($libname) . '.def' );
217 0 $self->_generate_msvc_def( $def, @files );
218 0 ▶ push @cmd, "$def" if -e "$def";
Branch: 1 branch
BranchTrueFalseTotal
if -e "$def" 0 0 0
219 }
220 else {
221 0 ▶ push @cmd, $os eq 'MSWin32' ? ('-shared') : ( '-shared', '-fPIC' );
Branch: 1 branch
BranchTrueFalseTotal
$os eq 'MSWin32' ? : 0 0 0
222 0 ▶ push @cmd, '-Wl,--export-all-symbols' if $os eq 'MSWin32' && $linker =~ /gcc|g\+\+|clang/;
Branch: 1 branch
BranchTrueFalseTotal
if $os eq "MSWin32" and $linker =~ /gcc|g\+\+|clang/u 0 0 0
Condition0%0/3
$os eq "MSWin32" and $linker =~ /gcc|g\+\+|clang/u
!ll&&!rl&&r
000
MC/DC0%0/2
$os eq "MSWin32" and $linker =~ /gcc|g\+\+|clang/u
$os eq "MSWin32" $linker =~ /gcc|g\+\+|clang/u
Truth table0%0/3
A and B
A= $os eq "MSWin32"B= $linker =~ /gcc|g\+\+|clang/u
ABresult
0X0
100
111
223 0 push @cmd, '-o', $libname->stringify;
224 }
225 0 ▶ push @cmd, '/Fe' . $libname->stringify if $msvc;
Branch: 1 branch
BranchTrueFalseTotal
if $msvc 0 0 0
226  
227 # MinGW Static Lib Fix: --whole-archive ensures unused symbols (like language runtimes) are kept
228 0 ▶ my $is_gcc = ( $linker =~ /gcc|g\+\+|clang/ || $cc =~ /gcc/ );
Condition0%0/3
$linker =~ /gcc|g\+\+|clang/u || $cc =~ /gcc/u
l!l&&r!l&&!r
000
MC/DC0%0/2
$linker =~ /gcc|g\+\+|clang/u || $cc =~ /gcc/u
$linker =~ /gcc|g\+\+|clang/u $cc =~ /gcc/u
Truth table0%0/3
A || B
A= $linker =~ /gcc|g\+\+|clang/uB= $cc =~ /gcc/u
ABresult
1X1
011
000
229 0 foreach my $f (@files) {
230 0 my $p = "$f";
231 0 ▶ if ( $is_gcc && $p =~ /\Q$Config{_a}\E$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_gcc and $p =~ /\Q$Affix::Build::Config{'_a'}\E$/u) { } 0 0 0
Condition0%0/3
$is_gcc and $p =~ /\Q$Affix::Build::Config{"_a"}\E$/u
!ll&&!rl&&r
000
MC/DC0%0/2
$is_gcc and $p =~ /\Q$Affix::Build::Config{"_a"}\E$/u
$is_gcc $p =~ /\Q$Affix::Build::Config{"_a"}\E$/u
Truth table0%0/3
A and B
A= $is_gccB= $p =~ /\Q$Affix::Build::Config{"_a"}\E$/u
ABresult
0X0
100
111
232 0 push @cmd, '-Wl,--whole-archive', $p, '-Wl,--no-whole-archive';
233 }
234 else {
235 0 push @cmd, $p;
236 }
237 }
238 0 my %seen;
239 0 for my $l (@libs) {
240 0 ▶ next if $seen{$l}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$l}++ 0 0 0
241 0 push @cmd, "-l$l";
242 }
243 0 push @cmd, @ldflags;
244 0 $self->_run(@cmd);
245 0 return $libname;
246 }
247  
248 # Helper to map extensions to method names
249 56 ▶ method _resolve_handler ($l) {
Subroutine _resolve_handler: called CC=22 SCAR=49.0
250  
251 # Normalize
252 56 ▶ if ( $l =~ /^(cpp|cxx|cc|c\+\+)$/ ) { return '_build_cpp'; }
Branch: 21 branches
BranchTrueFalseTotal
if ($l =~ /^(cpp|cxx|cc|c\+\+)$/u) { } 1 55 56
elsif ($l =~ /^(f|f90|f95|for|fortran)$/u) { } 0 55 55
elsif ($l =~ /^(ru?st?)$/u) { } 0 55 55
elsif ($l =~ /^(cs|csharp|c#)$/u) { } 0 55 55
elsif ($l =~ /^(fs|fsharp|f#)$/u) { } 0 55 55
elsif ($l =~ /^(s|asm|assembly)$/u) { } 0 55 55
elsif ($l =~ /^(adb|ads|ada)$/u) { } 0 55 55
elsif ($l =~ /^(hs|lhs|haskell)$/u) { } 0 55 55
elsif ($l =~ /^(cr|crystal)$/u) { } 0 55 55
elsif ($l =~ /^(fut|futhark)$/u) { } 0 55 55
elsif ($l =~ /^(pas|pp|pascal)$/u) { } 0 55 55
elsif ($l =~ /^(cbl|cob|cobol)$/u) { } 0 55 55
elsif ($l =~ /^(ml|ocaml)$/u) { } 0 55 55
elsif ($l =~ /^(e|eiffel)$/u) { } 0 55 55
elsif ($l =~ /^(go)$/u) { } 0 55 55
elsif ($l =~ /^(zig)$/u) { } 0 55 55
elsif ($l =~ /^(odin)$/u) { } 0 55 55
elsif ($l =~ /^(nim)$/u) { } 0 55 55
elsif ($l =~ /^(d|dlang)$/u) { } 0 55 55
elsif ($l =~ /^(swift)$/u) { } 0 55 55
elsif ($l =~ /^(v|vlang)$/u) { } 0 55 55
253 0 elsif ( $l =~ /^(f|f90|f95|for|fortran)$/ ) { return '_build_fortran'; }
254 0 elsif ( $l =~ /^(ru?st?)$/ ) { return '_build_rust'; }
255 0 elsif ( $l =~ /^(cs|csharp|c#)$/ ) { return '_build_csharp'; }
256 0 elsif ( $l =~ /^(fs|fsharp|f#)$/ ) { return '_build_fsharp'; }
257 0 elsif ( $l =~ /^(s|asm|assembly)$/ ) { return '_build_asm'; }
258 0 elsif ( $l =~ /^(adb|ads|ada)$/ ) { return '_build_ada'; }
259 0 elsif ( $l =~ /^(hs|lhs|haskell)$/ ) { return '_build_haskell'; }
260 0 elsif ( $l =~ /^(cr|crystal)$/ ) { return '_build_crystal'; }
261 0 elsif ( $l =~ /^(fut|futhark)$/ ) { return '_build_futhark'; }
262 0 elsif ( $l =~ /^(pas|pp|pascal)$/ ) { return '_build_pascal'; }
263 0 elsif ( $l =~ /^(cbl|cob|cobol)$/ ) { return '_build_cobol'; }
264 0 elsif ( $l =~ /^(ml|ocaml)$/ ) { return '_build_ocaml'; }
265 0 elsif ( $l =~ /^(e|eiffel)$/ ) { return '_build_eiffel'; }
266 0 elsif ( $l =~ /^(go)$/ ) { return '_build_go'; }
267 0 elsif ( $l =~ /^(zig)$/ ) { return '_build_zig'; }
268 0 elsif ( $l =~ /^(odin)$/ ) { return '_build_odin'; }
269 0 elsif ( $l =~ /^(nim)$/ ) { return '_build_nim'; }
270 0 elsif ( $l =~ /^(d|dlang)$/ ) { return '_build_d'; }
271 0 elsif ( $l =~ /^(swift)$/ ) { return '_build_swift'; }
272 0 elsif ( $l =~ /^(v|vlang)$/ ) { return '_build_v'; }
273  
274 # Fallback to C
275 55 return '_build_c';
276 }
277  
278 56 ▶ method _run (@cmd) {
Subroutine _run: called CC=5 SCAR=24.1
279 56 ▶ print STDERR "[Affix] Exec: @cmd\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 56 56
280  
281 # use Data::Dump;
282 # ddx \@cmd;
283 56 ▶ my ( $stdout, $stderr, $exit ) = capture {
Subroutine __ANON__: called CC=1 SCAR=0.0
284 56 system @cmd;
285 56 };
286 56 ▶ if ( !!$exit ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not !$exit) 0 56 56
287 0 ▶ warn $stdout if $stdout;
Branch: 1 branch
BranchTrueFalseTotal
if $stdout 0 0 0
288 0 ▶ warn $stderr if $stderr;
Branch: 1 branch
BranchTrueFalseTotal
if $stderr 0 0 0
289 0 my $rc = $exit >> 8;
290 0 croak "Command failed (Exit $rc): @cmd";
291 }
292 }
293  
294 56 ▶ method _can_run (@cmd) {
Subroutine _can_run: called CC=5 SCAR=16.5
295 56 for my $c (@cmd) {
296 56 ▶ return $c if MM->maybe_command($c);
Branch: 1 branch
BranchTrueFalseTotal
if "MM"->maybe_command($c) 0 56 56
297 56 for my $dir ( File::Spec->path ) {
298 448 my $abs = File::Spec->catfile( $dir, $c );
299 448 ▶ return $abs if MM->maybe_command($abs);
Branch: 1 branch
BranchTrueFalseTotal
if "MM"->maybe_command($abs) 56 392 448
300 }
301 }
302 0 return undef;
303 }
304  
305 # True when the given command (defaults to the C compiler) is MSVC 'cl'.
306 168 ▶ method _is_msvc ( $cmd = undef ) {
Subroutine _is_msvc: called CC=4 SCAR=15.2
307 168 ▶ $cmd //= $cc;
Condition66%2/3
$cmd //= $cc
l!l&&r!l&&!r
113550
MC/DC0%0/2
$cmd //= $cc
$cmd $cc
Truth table66%2/3
A //= B
A= $cmdB= $cc
ABresult
1X1
011
000
308 168 ▶ return defined $cmd && $cmd =~ /(?:^|[\\\/])cl(?:\.exe)?$/i;
Condition33%1/3
defined $cmd && $cmd =~ m[(?:^|[\\/])cl(?:\.exe)?$]iu
!ll&&!rl&&r
01680
MC/DC0%0/2
defined $cmd && $cmd =~ m[(?:^|[\\/])cl(?:\.exe)?$]iu
defined $cmd $cmd =~ m[(?:^|[\\/])cl(?:\.exe)?$]iu
Truth table33%1/3
A && B
A= defined $cmdB= $cmd =~ m[(?:^|[\\/])cl(?:\.exe)?$]iu
ABresult
0X0
100
111
309 }
310  
311 # Object/static-library extensions follow the active compiler, not perl's
312 # Config (Strawberry's Config reports .o/.a even when cl is selected).
313 0 ▶ method _obj_ext { $self->_is_msvc ? '.obj' : $Config{_o} }
Subroutine _obj_ext: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_msvc ? : 0 0 0
314 0 ▶ method _lib_ext { $self->_is_msvc ? '.lib' : $Config{_a} }
Subroutine _lib_ext: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_msvc ? : 0 0 0
315 0 ▶ method _base ($file) { return $file->basename(qr/\.[^.]+$/); }
Subroutine _base: not called CC=1 SCAR=6.9
316 #
317 55 ▶ method _build_c ( $src, $out, $mode ) {
Subroutine _build_c: called CC=6 SCAR=26.2
318 55 my $file = $src->{path};
319 55 my @local = @{ $src->{flags} };
320 55 ▶ if ( $self->_is_msvc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_msvc) 0 55 55
321 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "dynamic") 0 0 0
322 0 $self->_run( $cc, '/nologo', '/LD', @cflags, @local, "$file", '/Fe' . "$out", @ldflags );
323 0 return $out;
324 }
325 0 my $obj = $build_dir->child( $self->_base($file) . $self->_obj_ext );
326 0 $self->_run( $cc, '/nologo', '/c', @cflags, @local, "$file", '/Fo' . "$obj" );
327 0 return { file => $obj };
328 }
329 55 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 55 0 55
330  
331 # Combine Global CFLAGS + Local Flags + Global LDFLAGS
332 55 my @cmd = ( $cc, '-shared', @cflags, @local, "$file", '-o', "$out", @ldflags );
333 55 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 55 0 55
334 55 $self->_run(@cmd);
335 55 return $out;
336 }
337 else {
338 0 my $obj = $build_dir->child( $self->_base($file) . $Config{_o} );
339  
340 # Combine Global CFLAGS + Local Flags
341 0 my @cmd = ( $cc, '-c', @cflags, @local, "$file", '-o', "$obj" );
342 0 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
343 0 $self->_run(@cmd);
344 0 return { file => $obj };
345 }
346 }
347  
348 1 ▶ method _build_cpp ( $src, $out, $mode ) {
Subroutine _build_cpp: called CC=6 SCAR=26.2
349 1 my $file = $src->{path};
350 1 my @local = @{ $src->{flags} };
351 1 ▶ if ( $self->_is_msvc($cxx) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_msvc($cxx)) 0 1 1
352 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "dynamic") 0 0 0
353 0 $self->_run( $cxx, '/nologo', '/LD', @cxxflags, @local, "$file", '/Fe' . "$out", @ldflags );
354 0 return $out;
355 }
356 0 my $obj = $build_dir->child( $self->_base($file) . $self->_obj_ext );
357 0 $self->_run( $cxx, '/nologo', '/c', @cxxflags, @local, "$file", '/Fo' . "$obj" );
358 0 return { file => $obj };
359 }
360 1 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 1 0 1
361 1 my @cmd = ( $cxx, '-shared', @cxxflags, @local, "$file", '-o', "$out", @ldflags );
362 1 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 1 0 1
363 1 $self->_run(@cmd);
364 1 return $out;
365 }
366 else {
367 0 my $obj = $build_dir->child( $self->_base($file) . $Config{_o} );
368 0 my @cmd = ( $cxx, '-c', @cxxflags, @local, "$file", '-o', "$obj" );
369 0 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
370 0 $self->_run(@cmd);
371 0 return { file => $obj };
372 }
373 }
374  
375 #~ https://fasterthanli.me/series/making-our-own-executable-packer/part-5
376 #~ https://stackoverflow.com/questions/71704813/writing-and-linking-shared-libraries-in-assembly-32-bit
377 #~ https://github.com/therealdreg/nasm_linux_x86_64_pure_sharedlib
378 0 ▶ method _build_asm ( $src, $out, $mode ) {
Subroutine _build_asm: not called CC=16 SCAR=56.1
379 0 my $file = $src->{path};
380 0 my @local = @{ $src->{flags} };
381 0 my $obj = $build_dir->child( $self->_base($file) . $self->_obj_ext );
382  
383 # Detect Assembler Type: .asm (Intel/NASM) vs .s (AT&T/CC)
384 0 my $is_nasm = ( $file =~ /\.asm$/i );
385 0 my $compiled = 0;
386 0 ▶ if ($is_nasm) { # .asm = Intel syntax = NASM
Branch: 1 branch
BranchTrueFalseTotal
if ($is_nasm) { } 0 0 0
387 0 ▶ my $nasm = $self->_can_run('nasm') // croak "NASM not found";
Condition0%0/2
$self->_can_run("nasm") // croak("NASM not found")
l!l
00
MC/DC0%0/1
$self->_can_run("nasm") // croak("NASM not found")
$self->_can_run("nasm")
Truth table0%0/2
A
A= $self->_can_run("nasm")
Aresult
11
00
388 0 ▶ my $fmt = $os eq 'MSWin32' ? 'win64' : ( $os eq 'darwin' ? 'macho64' : 'elf64' );
Branch: 2 branches
BranchTrueFalseTotal
$os eq 'MSWin32' ? : 0 0 0
$os eq 'darwin' ? : 0 0 0
389 0 $self->_run( $nasm, '-f', $fmt, @local, "$file", '-o', "$obj" );
390 0 $compiled = 1;
391 }
392 else { # .s = AT&T/GNU syntax = System CC
393 0 ▶ if ( $cc && $self->_can_run($cc) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cc and $self->_can_run($cc)) 0 0 0
Condition0%0/3
$cc and $self->_can_run($cc)
!ll&&!rl&&r
000
MC/DC0%0/2
$cc and $self->_can_run($cc)
$cc $self->_can_run($cc)
Truth table0%0/3
A and B
A= $ccB= $self->_can_run($cc)
ABresult
0X0
100
111
394 0 my @cmd = ( $cc, '-c', @local, "$file", '-o', "$obj" );
395 0 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
396 0 $self->_run(@cmd);
397 0 $compiled = 1;
398 }
399 }
400 0 ▶ croak 'Assembly failed' unless $compiled && -e "$obj";
Branch: 1 branch
BranchTrueFalseTotal
unless $compiled and -e "$obj" 0 0 0
Condition0%0/3
$compiled and -e "$obj"
!ll&&!rl&&r
000
MC/DC0%0/2
$compiled and -e "$obj"
$compiled -e "$obj"
Truth table0%0/3
A and B
A= $compiledB= -e "$obj"
ABresult
0X0
100
111
401 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "dynamic") 0 0 0
402 0 ▶ if ( $self->_is_msvc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_msvc) 0 0 0
403 0 my $def = $build_dir->child( $self->_base($file) . '.def' );
404 0 $self->_generate_msvc_def( $def, $obj );
405 0 my @cmd = ( $linker, '/nologo', '/LD', "$obj", '/Fe' . "$out" );
406 0 ▶ push @cmd, "$def" if -e "$def";
Branch: 1 branch
BranchTrueFalseTotal
if -e "$def" 0 0 0
407 0 push @cmd, @ldflags, '/link', '/NOENTRY';
408 0 $self->_run(@cmd);
409 0 return $out;
410 }
411 0 my @cmd = ( $linker, '-shared', "$obj", '-o', "$out", @ldflags );
412 0 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
413 0 ▶ if ( $os eq 'MSWin32' && $linker =~ /gcc|g\+\+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($os eq "MSWin32" and $linker =~ /gcc|g\+\+/u) 0 0 0
Condition0%0/3
$os eq "MSWin32" and $linker =~ /gcc|g\+\+/u
!ll&&!rl&&r
000
MC/DC0%0/2
$os eq "MSWin32" and $linker =~ /gcc|g\+\+/u
$os eq "MSWin32" $linker =~ /gcc|g\+\+/u
Truth table0%0/3
A and B
A= $os eq "MSWin32"B= $linker =~ /gcc|g\+\+/u
ABresult
0X0
100
111
414 0 push @cmd, '-Wl,--export-all-symbols';
415 }
416 0 $self->_run(@cmd);
417 0 return $out;
418 }
419 0 return { file => $obj };
420 }
421  
422 #~ https://blog.asleson.org/2021/02/23/how-to-writing-a-c-shared-library-in-rust/
423 0 ▶ method _rust_target () {
Subroutine _rust_target: not called CC=7 SCAR=40.3
424 0 ▶ return undef unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
425 0 ▶ my $arch = ( $Config{archname} =~ /arm64|aarch64/i ) ? 'aarch64' : ( $Config{ptrsize} == 4 ) ? 'i686' : 'x86_64';
Branch: 2 branches
BranchTrueFalseTotal
$Affix::Build::Config{'archname'} =~ /arm64|aarch64/iu ? : 0 0 0
$Affix::Build::Config{'ptrsize'} == 4 ? : 0 0 0
426 0 ▶ if ( $self->_is_msvc ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_msvc) { } 0 0 0
elsif ($cc =~ /gcc/u) { } 0 0 0
427 0 return "$arch-pc-windows-msvc";
428 }
429 elsif ( $cc =~ /gcc/ ) {
430 0 ▶ return $arch eq 'aarch64' ? 'aarch64-pc-windows-gnullvm' : "$arch-pc-windows-gnu";
Branch: 1 branch
BranchTrueFalseTotal
$arch eq 'aarch64' ? : 0 0 0
431 }
432 0 return undef;
433 }
434  
435 0 ▶ method _build_rust ( $src, $out, $mode ) {
Subroutine _build_rust: not called CC=6 SCAR=37.4
436 0 my $file = $src->{path};
437 0 my @local = @{ $src->{flags} };
438 0 ▶ my $rc = $self->_can_run('rustc') // croak "Rustc not found";
Condition0%0/2
$self->_can_run("rustc") // croak("Rustc not found")
l!l
00
MC/DC0%0/1
$self->_can_run("rustc") // croak("Rustc not found")
$self->_can_run("rustc")
Truth table0%0/2
A
A= $self->_can_run("rustc")
Aresult
11
00
439 0 my $target = $self->_rust_target;
440 0 ▶ my @target_flag = $target ? ( '--target', $target ) : ();
Branch: 1 branch
BranchTrueFalseTotal
$target ? : 0 0 0
441 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
442 0 $self->_run( $rc, '--crate-type', 'cdylib', @target_flag, @local, '-o', "$out", "$file" );
443 0 return $out;
444 }
445 else {
446 0 my $lib = $build_dir->child( $self->_base($file) . $Config{_a} );
447 0 my @cmd = ( $rc, '--crate-type=staticlib', '--emit=link', '-C', 'panic=abort', @target_flag, @local, "$file", '-o', "$lib" );
448 0 ▶ if ( $os ne 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($os ne "MSWin32") 0 0 0
449 0 push @cmd, '-C', 'relocation-model=pic';
450 }
451 0 $self->_run(@cmd);
452 0 ▶ my @deps = $os eq 'MSWin32' ? qw(ws2_32 userenv bcrypt advapi32 ntdll) : qw(dl pthread m);
Branch: 1 branch
BranchTrueFalseTotal
$os eq 'MSWin32' ? : 0 0 0
453 0 return { file => $lib, libs => \@deps };
454 }
455 }
456  
457 #~ https://medium.com/@walkert/fun-building-shared-libraries-in-go-639500a6a669
458 #~ https://github.com/vladimirvivien/go-cshared-examples
459 0 ▶ method _build_go ( $src, $out, $mode ) {
Subroutine _build_go: not called CC=7 SCAR=40.3
460 0 my $file = $src->{path};
461 0 my @local = @{ $src->{flags} }; # passed to go build args
462  
463 # MinGW GCC 8.3.0 had known issues guaranteeing the 16-byte stack alignment required by the
464 # Go runtime (and SSE/AVX instructions) on Windows x64. If Perl calls your library with a
465 # 8-byte aligned stack (which was common in older GCC optimization flags), Go will segfault
466 # immediately when it tries to access the stack.
467 # Ensure GOARCH and CC match Perl's architecture
468 0 ▶ local $ENV{GOARCH} = $ENV{GOARCH} // do {
Condition0%0/3
$ENV{"GOARCH"} // do { $Affix::Build::Config{"archname"} =~ /arm64|aarch64/iu ? "arm64" : ($Affix::Build::Config{"ptrsize"} == 4 ? 386 : "amd64") }
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"GOARCH"} // do { $Affix::Build::Config{"archname"} =~ /arm64|aarch64/iu ? "arm64" : ($Affix::Build::Config{"ptrsize"} == 4 ? 386 : "amd64") }
$ENV{"GOARCH"} do { $Affix::Build::Config{"archname"} =~ /arm64|aarch64/iu ? "arm64" : ($Affix::Build::Config{"ptrsize"} == 4 ? 386 : "amd64") }
Truth table0%0/3
A // B
A= $ENV{"GOARCH"}B= do { $Affix::Build::Config{"archname"} =~ /arm64|aarch64/iu ? "arm64" : ($Affix::Build::Config{"ptrsize"} == 4 ? 386 : "amd64") }
ABresult
1X1
011
000
469 0 ▶ ( $Config{archname} =~ /arm64|aarch64/i ) ? 'arm64' : ( $Config{ptrsize} == 4 ) ? '386' : 'amd64';
Branch: 2 branches
BranchTrueFalseTotal
$Affix::Build::Config{'archname'} =~ /arm64|aarch64/iu ? : 0 0 0
$Affix::Build::Config{'ptrsize'} == 4 ? : 0 0 0
470 };
471 0 ▶ local $ENV{CC} = $ENV{CC} // $self->cc;
Condition0%0/3
$ENV{"CC"} // $self->cc
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"CC"} // $self->cc
$ENV{"CC"} $self->cc
Truth table0%0/3
A // B
A= $ENV{"CC"}B= $self->cc
ABresult
1X1
011
000
472 0 ▶ push @local, q[-ldflags "-extldflags '-static -static-libgcc -static-libstdc++'"] if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 0 0
473 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
474 0 $self->_run( 'go', 'build', '-buildmode=c-shared', @local, '-o', "$out", "$file" );
475 0 return $out;
476 }
477 else {
478 0 my $lib = $build_dir->child( $self->_base($file) . $Config{_a} );
479 0 $self->_run( 'go', 'build', '-buildmode=c-archive', @local, '-o', "$lib", "$file" );
480 0 return { file => $lib, libs => ['pthread'] };
481 }
482 }
483  
484 #~ https://odin-lang.org/news/calling-odin-from-python/
485 #~ https://odin-lang.org/docs/install/#release-requirements--notes
486 0 ▶ method _build_odin ( $src, $out, $mode ) {
Subroutine _build_odin: not called CC=6 SCAR=37.4
487 0 my $file = $src->{path};
488 0 my @local = @{ $src->{flags} };
489 0 ▶ my $odin = $self->_can_run('odin') // croak "Odin not found";
Condition0%0/2
$self->_can_run("odin") // croak("Odin not found")
l!l
00
MC/DC0%0/1
$self->_can_run("odin") // croak("Odin not found")
$self->_can_run("odin")
Truth table0%0/2
A
A= $self->_can_run("odin")
Aresult
11
00
490 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
491 0 $self->_run( $odin, 'build', "$file", '-file', '-build-mode:dll', @local, "-out:$out" );
492 0 return $out;
493 }
494 else {
495 0 my $obj = $build_dir->child( $self->_base($file) . $Config{_o} );
496 0 my @cmd = ( $odin, 'build', "$file", '-file', '-build-mode:obj', @local, "-out:$obj" );
497 0 ▶ push @cmd, '-reloc-mode:pic' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
498 0 $self->_run(@cmd);
499 0 ▶ unless ( $obj->exists ) { # Attempt to find it if Odin misnamed it (e.g. .obj vs .o)
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->exists) 0 0 0
500 0 my $cwd_obj = Path::Tiny::path( $self->_base($file) . $Config{_o} );
501 0 ▶ $cwd_obj->move($obj) if $cwd_obj->exists;
Branch: 1 branch
BranchTrueFalseTotal
if $cwd_obj->exists 0 0 0
502 }
503 0 return { file => $obj };
504 }
505 }
506  
507 #~ https://dlang.org/articles/dll-linux.html#dso9
508 #~ dmd -c dll.d -fPIC
509 #~ dmd -oflibdll.so dll.o -shared -defaultlib=libphobos2.so -L-rpath=/path/to/where/shared/library/is
510 0 ▶ method _build_d ( $src, $out, $mode ) {
Subroutine _build_d: not called CC=5 SCAR=34.0
511 0 my $file = $src->{path};
512 0 ▶ my $dmd = $self->_can_run(qw[dmd ldc2 gdc]) // croak "D compiler not found";
Condition0%0/2
$self->_can_run("dmd", "ldc2", "gdc") // croak("D compiler not found")
l!l
00
MC/DC0%0/1
$self->_can_run("dmd", "ldc2", "gdc") // croak("D compiler not found")
$self->_can_run("dmd", "ldc2", "gdc")
Truth table0%0/2
A
A= $self->_can_run("dmd", "ldc2", "gdc")
Aresult
11
00
513 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
514 0 my @cmd = ( $dmd, '-shared', "$file", "-of=$out" );
515 0 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
516 0 $self->_run(@cmd);
517 0 return $out;
518 }
519 else {
520 0 my $lib = $build_dir->child( $self->_base($file) . $Config{_a} );
521 0 my @cmd = ( $dmd, '-lib', "$file", "-of=$lib" );
522 0 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
523 0 $self->_run(@cmd);
524 0 return { file => $lib };
525 }
526 }
527 0 ▶ method _build_csharp ( $file, $out, $mode ) { $self->_build_dotnet( $file, $out, $mode, 'cs' ); }
Subroutine _build_csharp: not called CC=1 SCAR=6.9
528  
529 #~ https://github.com/secana/Native-FSharp-Library
530 #~ https://secanablog.wordpress.com/2020/02/01/writing-a-native-library-in-f-which-can-be-called-from-c/
531 0 ▶ method _build_fsharp ( $file, $out, $mode ) { $self->_build_dotnet( $file, $out, $mode, 'fs' ); }
Subroutine _build_fsharp: not called CC=1 SCAR=6.9
532  
533 0 ▶ method _build_dotnet ( $src, $out, $mode, $lang ) {
Subroutine _build_dotnet: not called CC=10 SCAR=47.0
534 0 my $file = $src->{path};
535 0 ▶ my $dotnet = $self->_can_run('dotnet') // croak "Dotnet not found";
Condition0%0/2
$self->_can_run("dotnet") // croak("Dotnet not found")
l!l
00
MC/DC0%0/1
$self->_can_run("dotnet") // croak("Dotnet not found")
$self->_can_run("dotnet")
Truth table0%0/2
A
A= $self->_can_run("dotnet")
Aresult
11
00
536 0 my $proj_dir = $build_dir->child( "dotnet_${lang}_" . $self->_base($file) );
537 0 $proj_dir->mkpath;
538 0 $file->copy( $proj_dir->child( $file->basename ) );
539 0 ▶ my $ext = $lang eq 'fs' ? 'fsproj' : 'csproj';
Branch: 1 branch
BranchTrueFalseTotal
$lang eq 'fs' ? : 0 0 0
540 0 my $proj = $proj_dir->child("Build.$ext");
541 0 ▶ my $lib_type = ( $mode eq 'dynamic' ) ? 'Shared' : 'Static';
Branch: 1 branch
BranchTrueFalseTotal
$mode eq 'dynamic' ? : 0 0 0
542 0 ▶ my $items = $lang eq 'fs' ? '<ItemGroup><Compile Include="**/*.fs" /></ItemGroup>' : '';
Branch: 1 branch
BranchTrueFalseTotal
$lang eq 'fs' ? : 0 0 0
543 0 $proj->spew_utf8(<<"XML");
544 <Project Sdk="Microsoft.NET.Sdk">
545 <PropertyGroup>
546 <TargetFramework>net8.0</TargetFramework>
547 <PublishAot>true</PublishAot>
548 <NativeLib>$lib_type</NativeLib>
549 <SelfContained>true</SelfContained>
550 </PropertyGroup>
551 $items
552 </Project>
553 XML
554 0 my $out_dir = $proj_dir->child('out');
555 0 ▶ my $rid = $os eq 'MSWin32' ? 'win-x64' : 'linux-x64';
Branch: 1 branch
BranchTrueFalseTotal
$os eq 'MSWin32' ? : 0 0 0
556  
557 # Local flags? Dotnet CLI args are tricky, assuming they aremsbuild props?
558 # Ignoring for now to keep it safe, or pass as raw args if user knows what they do.
559 0 my @local = @{ $src->{flags} };
560 0 $self->_run( "$dotnet", 'publish', "$proj", '-r', $rid, '-o', "$out_dir", @local );
561 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
562 0 my $dll_ext = $Config{so};
563 0 ▶ $dll_ext = ".$dll_ext" unless $dll_ext =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
unless $dll_ext =~ /^\./u 0 0 0
564 0 my ($artifact) = grep {/\Q$dll_ext\E$/} $out_dir->children;
565 0 ▶ croak "Dotnet build failed" unless $artifact;
Branch: 1 branch
BranchTrueFalseTotal
unless $artifact 0 0 0
566 0 Path::Tiny::path($artifact)->move($out);
567 0 return $out;
568 }
569 else {
570 0 my $lib_ext = $Config{_a};
571 0 my ($artifact) = grep {/\Q$lib_ext\E$/} $out_dir->children;
572 0 ▶ croak "Dotnet build failed" unless $artifact;
Branch: 1 branch
BranchTrueFalseTotal
unless $artifact 0 0 0
573 0 return { file => Path::Tiny::path($artifact) };
574 }
575 }
576  
577 #~ https://ziglang.org/documentation/0.13.0/#Exporting-a-C-Library
578 #~ zig build-lib mathtest.zig -dynamic
579 0 ▶ method _build_zig ( $src, $out, $mode ) {
Subroutine _build_zig: not called CC=4 SCAR=30.0
580 0 my $file = $src->{path};
581 0 my @local = @{ $src->{flags} };
582 0 ▶ my $zig = $self->_can_run('zig') // croak "Zig not found";
Condition0%0/2
$self->_can_run("zig") // croak("Zig not found")
l!l
00
MC/DC0%0/1
$self->_can_run("zig") // croak("Zig not found")
$self->_can_run("zig")
Truth table0%0/2
A
A= $self->_can_run("zig")
Aresult
11
00
583 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
584 0 $self->_run( $zig, 'build-lib', '-dynamic', @local, "$file", "-femit-bin=$out" );
585 0 return $out;
586 }
587 else {
588 0 my $lib = $build_dir->child( $self->_base($file) . $Config{_a} );
589 0 $self->_run( $zig, 'build-lib', '-static', @local, "$file", "-femit-bin=$lib" );
590 0 ▶ return { file => $lib, libs => ( $os eq 'MSWin32' ? ['ntdll'] : [] ) };
Branch: 1 branch
BranchTrueFalseTotal
$os eq 'MSWin32' ? : 0 0 0
591 }
592 }
593  
594 0 ▶ method _build_fortran ( $src, $out, $mode ) {
Subroutine _build_fortran: not called CC=6 SCAR=37.4
595 0 my $file = $src->{path};
596 0 my @local = @{ $src->{flags} };
597 0 ▶ my $fc = $self->_can_run(qw[gfortran ifx ifort]) // croak "No Fortran compiler";
Condition0%0/2
$self->_can_run("gfortran", "ifx", "ifort") // croak("No Fortran compiler")
l!l
00
MC/DC0%0/1
$self->_can_run("gfortran", "ifx", "ifort") // croak("No Fortran compiler")
$self->_can_run("gfortran", "ifx", "ifort")
Truth table0%0/2
A
A= $self->_can_run("gfortran", "ifx", "ifort")
Aresult
11
00
598 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
599 0 my @cmd = ( $fc, '-shared', @local, "$file", '-o', "$out", @ldflags );
600 0 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
601 0 $self->_run(@cmd);
602 0 return $out;
603 }
604 else {
605 0 my $obj = $build_dir->child( $self->_base($file) . $Config{_o} );
606 0 my @cmd = ( $fc, '-c', @local, "$file", '-o', "$obj" );
607 0 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
608 0 $self->_run(@cmd);
609 0 ▶ return { file => $obj, libs => ( $os eq 'MSWin32' ? [] : ['gfortran'] ) };
Branch: 1 branch
BranchTrueFalseTotal
$os eq 'MSWin32' ? : 0 0 0
610 }
611 }
612  
613 #~ https://peterme.net/dynamic-libraries-in-nim.html
614 0 ▶ method _build_nim ( $src, $out, $mode ) {
Subroutine _build_nim: not called CC=3 SCAR=24.8
615 0 my $file = $src->{path};
616 0 ▶ my $nim = $self->_can_run('nim') // croak "Nim not found";
Condition0%0/2
$self->_can_run("nim") // croak("Nim not found")
l!l
00
MC/DC0%0/1
$self->_can_run("nim") // croak("Nim not found")
$self->_can_run("nim")
Truth table0%0/2
A
A= $self->_can_run("nim")
Aresult
11
00
617 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
618 0 $self->_run( $nim, 'c', '--app:lib', '--noMain', '--cc:c', "--out:$out", "$file" );
619 0 return $out;
620 }
621 else {
622 0 my $lib = $build_dir->child( $self->_base($file) . $Config{_a} );
623 0 $self->_run( $nim, 'c', '--app:staticlib', '--noMain', '--cc:c', '--nimcache:' . $build_dir, "--out:$lib", "$file" );
624 0 return { file => $lib };
625 }
626 }
627  
628 #~ https://www.rangakrish.com/index.php/2023/04/02/building-v-language-dll/
629 #~ https://dev.to/piterweb/how-to-create-and-use-dlls-on-vlang-1p13
630 0 ▶ method _build_v ( $src, $out, $mode ) {
Subroutine _build_v: not called CC=3 SCAR=24.8
631 0 my $file = $src->{path};
632 0 ▶ my $v = $self->_can_run('v') // croak "V not found";
Condition0%0/2
$self->_can_run("v") // croak("V not found")
l!l
00
MC/DC0%0/1
$self->_can_run("v") // croak("V not found")
$self->_can_run("v")
Truth table0%0/2
A
A= $self->_can_run("v")
Aresult
11
00
633 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
634 0 $self->_run( $v, '-shared', '-o', "$out", "$file" );
635 0 return $out;
636 }
637 else {
638 0 my $c_file = $build_dir->child( $self->_base($file) . '.c' );
639 0 $self->_run( $v, '-o', "$c_file", "$file" );
640 0 return $self->_build_c( { path => $c_file }, undef, 'static' );
641 }
642 }
643  
644 #~ swiftc point.swift -emit-module -emit-library
645 #~ https://forums.swift.org/t/creating-a-c-accessible-shared-library-in-swift/45329/5
646 #~ https://theswiftdev.com/building-static-and-dynamic-swift-libraries-using-the-swift-compiler/#should-i-choose-dynamic-or-static-linking
647 0 ▶ method _build_swift ( $src, $out, $mode ) {
Subroutine _build_swift: not called CC=3 SCAR=24.8
648 0 my $file = $src->{path};
649 0 ▶ my $sc = $self->_can_run('swiftc') // croak "Swiftc not found";
Condition0%0/2
$self->_can_run("swiftc") // croak("Swiftc not found")
l!l
00
MC/DC0%0/1
$self->_can_run("swiftc") // croak("Swiftc not found")
$self->_can_run("swiftc")
Truth table0%0/2
A
A= $self->_can_run("swiftc")
Aresult
11
00
650  
651 # Swiftc uses -emit-library for both, just differs on output filename usually
652 # But for static we usually want -static if available or just .a
653 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
654 0 $self->_run( $sc, '-emit-library', "$file", '-o', "$out" );
655 0 return $out;
656 }
657 else {
658 0 my $lib = $build_dir->child( $self->_base($file) . $Config{_a} );
659  
660 # Note: Swift static linking is complex on Linux, but -emit-library -static usually works
661 0 $self->_run( $sc, '-emit-library', '-static', '-parse-as-library', "$file", '-o', "$lib" );
662 0 return { file => $lib };
663 }
664 }
665  
666 #~ https://gcc.gnu.org/onlinedocs/gcc-3.4.0/gnat_ug_unx/Creating-an-Ada-Library.html
667 0 ▶ method _build_ada ( $src, $out, $mode ) {
Subroutine _build_ada: not called CC=6 SCAR=37.4
668 0 my $file = $src->{path};
669 0 ▶ my $gnat = $self->_can_run('gnatmake') // croak "GNAT not found";
Condition0%0/2
$self->_can_run("gnatmake") // croak("GNAT not found")
l!l
00
MC/DC0%0/1
$self->_can_run("gnatmake") // croak("GNAT not found")
$self->_can_run("gnatmake")
Truth table0%0/2
A
A= $self->_can_run("gnatmake")
Aresult
11
00
670  
671 # Ada compilation is usually to Object first
672 0 my $obj = $build_dir->child( $self->_base($file) . $Config{_o} );
673 0 my @cmd = ( $gnat, '-c', '-u', "$file" );
674 0 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
675  
676 # GNAT often outputs to CWD
677 0 $self->_run(@cmd);
678 0 my $cwd_obj = Path::Tiny::path( $self->_base($file) . $Config{_o} );
679 0 ▶ $cwd_obj->move($obj) if $cwd_obj->exists && $cwd_obj->absolute ne $obj->absolute;
Branch: 1 branch
BranchTrueFalseTotal
if $cwd_obj->exists and $cwd_obj->absolute ne $obj->absolute 0 0 0
Condition0%0/3
$cwd_obj->exists and $cwd_obj->absolute ne $obj->absolute
!ll&&!rl&&r
000
MC/DC0%0/2
$cwd_obj->exists and $cwd_obj->absolute ne $obj->absolute
$cwd_obj->exists $cwd_obj->absolute ne $obj->absolute
Truth table0%0/3
A and B
A= $cwd_obj->existsB= $cwd_obj->absolute ne $obj->absolute
ABresult
0X0
100
111
680 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "dynamic") 0 0 0
681  
682 # Link the object to shared
683 # We use the generic linker logic for this single file
684 0 my $linker = $self->cc;
685 0 $self->_run( $linker, '-shared', '-o', "$out", "$obj" );
686 0 return $out;
687 }
688 0 return { file => $obj, libs => ['gnat'] };
689 }
690  
691 #~ https://github.com/bennoleslie/haskell-shared-example
692 #~ https://www.hobson.space/posts/haskell-foreign-library/
693 0 ▶ method _build_haskell ( $src, $out, $mode ) {
Subroutine _build_haskell: not called CC=5 SCAR=34.0
694 0 my $file = $src->{path};
695 0 ▶ my $ghc = $self->_can_run('ghc') // croak "GHC not found";
Condition0%0/2
$self->_can_run("ghc") // croak("GHC not found")
l!l
00
MC/DC0%0/1
$self->_can_run("ghc") // croak("GHC not found")
$self->_can_run("ghc")
Truth table0%0/2
A
A= $self->_can_run("ghc")
Aresult
11
00
696 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
697 0 my @cmd = ( $ghc, '-shared', '-dynamic', "$file", '-o', "$out" );
698 0 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
699 0 $self->_run(@cmd);
700 0 return $out;
701 }
702 else {
703 0 my $obj = $build_dir->child( $self->_base($file) . $Config{_o} );
704 0 my @cmd = ( $ghc, '-c', "$file", '-o', "$obj", '-no-hs-main' );
705 0 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
706 0 $self->_run(@cmd);
707 0 return { file => $obj };
708 }
709 }
710  
711 #~ https://github.com/crystal-lang/crystal/issues/921#issuecomment-2413541412
712 0 ▶ method _build_crystal ( $src, $out, $mode ) {
Subroutine _build_crystal: not called CC=4 SCAR=30.0
713 0 my $file = $src->{path};
714 0 ▶ my $cr = $self->_can_run('crystal') // croak "Crystal not found";
Condition0%0/2
$self->_can_run("crystal") // croak("Crystal not found")
l!l
00
MC/DC0%0/1
$self->_can_run("crystal") // croak("Crystal not found")
$self->_can_run("crystal")
Truth table0%0/2
A
A= $self->_can_run("crystal")
Aresult
11
00
715 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
716  
717 # Experimental: Attempt to pass linker flags
718 # Crystal doesn't have a native 'build shared' flag easily exposed
719 # It prefers static binaries.
720 0 $self->_run( $cr, 'build', "$file", '--link-flags', '-shared', '-o', "$out" );
721 0 return $out;
722 }
723 else {
724 0 my $obj = $build_dir->child( $self->_base($file) . $Config{_o} );
725 0 my @cmd = ( $cr, 'build', '--emit', 'obj', "$file", '-o', "$obj" );
726 0 ▶ push @cmd, '--link-flags', '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
727 0 $self->_run(@cmd);
728 0 return { file => $obj, libs => [ 'pcre', 'gc' ] };
729 }
730 }
731  
732 #~ https://futhark.readthedocs.io/en/stable/usage.html
733 0 ▶ method _build_futhark ( $src, $out, $mode ) {
Subroutine _build_futhark: not called CC=2 SCAR=17.9
734 0 my $file = $src->{path};
735 0 ▶ my $fut = $self->_can_run('futhark') // croak "Futhark not found";
Condition0%0/2
$self->_can_run("futhark") // croak("Futhark not found")
l!l
00
MC/DC0%0/1
$self->_can_run("futhark") // croak("Futhark not found")
$self->_can_run("futhark")
Truth table0%0/2
A
A= $self->_can_run("futhark")
Aresult
11
00
736  
737 # Futhark -> C
738 0 my $c_file = $build_dir->child( $self->_base($file) . '.c' );
739 0 my $prefix = $build_dir->child( $self->_base($file) );
740 0 $self->_run( $fut, 'c', '--library', "$file", '-o', "$prefix" );
741  
742 # Reuse C builder
743 0 return $self->_build_c( { path => $c_file }, $out, $mode );
744 }
745  
746 0 ▶ method _build_pascal ( $src, $out, $mode ) {
Subroutine _build_pascal: not called CC=4 SCAR=30.0
747 0 my $file = $src->{path};
748 0 ▶ my $fpc = $self->_can_run('fpc') // croak "FPC not found";
Condition0%0/2
$self->_can_run("fpc") // croak("FPC not found")
l!l
00
MC/DC0%0/1
$self->_can_run("fpc") // croak("FPC not found")
$self->_can_run("fpc")
Truth table0%0/2
A
A= $self->_can_run("fpc")
Aresult
11
00
749 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
750  
751 # Free Pascal needs 'library' keyword in source for shared libs usually
752 # -CD creates dynamic lib
753 0 $self->_run( $fpc, '-CD', "$file", "-o$out" );
754 0 return $out;
755 }
756 else {
757 0 my $obj = $build_dir->child( $self->_base($file) . $Config{_o} );
758 0 my @cmd = ( $fpc, '-Cn', "$file", "-o$obj" );
759 0 ▶ push @cmd, '-Cg' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
760 0 $self->_run(@cmd);
761 0 return { file => $obj };
762 }
763 }
764  
765 0 ▶ method _build_cobol ( $src, $out, $mode ) {
Subroutine _build_cobol: not called CC=5 SCAR=34.0
766 0 ▶ my $cobc = $self->_can_run('cobc') // croak "GnuCOBOL not found";
Condition0%0/2
$self->_can_run("cobc") // croak("GnuCOBOL not found")
l!l
00
MC/DC0%0/1
$self->_can_run("cobc") // croak("GnuCOBOL not found")
$self->_can_run("cobc")
Truth table0%0/2
A
A= $self->_can_run("cobc")
Aresult
11
00
767 0 ▶ my $file = ref $src ? $src->{path} : $src;
Branch: 1 branch
BranchTrueFalseTotal
ref $src ? : 0 0 0
768 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'dynamic') { } 0 0 0
769  
770 # -b = build dynamic module
771 0 $self->_run( $cobc, '-b', "$file", '-o', "$out" );
772 0 return $out;
773 }
774 else {
775 0 my $obj = $build_dir->child( $self->_base($file) . $Config{_o} );
776 0 my @cmd = ( $cobc, '-c', "$file", '-o', "$obj" );
777 0 ▶ push @cmd, '-fPIC' unless $os eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
unless $os eq "MSWin32" 0 0 0
778 0 $self->_run(@cmd);
779 0 return { file => $obj, libs => ['cob'] };
780 }
781 }
782  
783 0 ▶ method _build_ocaml ( $src, $out, $mode ) {
Subroutine _build_ocaml: not called CC=4 SCAR=30.0
784 0 ▶ my $ml = $self->_can_run('ocamlopt') // croak "OCaml not found";
Condition0%0/2
$self->_can_run("ocamlopt") // croak("OCaml not found")
l!l
00
MC/DC0%0/1
$self->_can_run("ocamlopt") // croak("OCaml not found")
$self->_can_run("ocamlopt")
Truth table0%0/2
A
A= $self->_can_run("ocamlopt")
Aresult
11
00
785 0 ▶ my $file = ref $src ? $src->{path} : $src;
Branch: 1 branch
BranchTrueFalseTotal
ref $src ? : 0 0 0
786 0 ▶ if ( $mode eq 'dynamic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "dynamic") 0 0 0
787  
788 # ocamlopt -shared -o lib.so file.ml
789 0 $self->_run( $ml, '-shared', "$file", '-o', "$out" );
790 0 return $out;
791 }
792 0 my $obj = $build_dir->child( $self->_base($file) . $Config{_o} );
793 0 $self->_run( $ml, '-output-obj', "$file", '-o', "$obj" );
794 0 return { file => $obj };
795 }
796  
797 #~ https://wiki.liberty-eiffel.org/index.php/Compile
798 #~ https://svn.eiffel.com/eiffelstudio-public/branches/Eiffel_54/Delivery/docs/papers/dll.html
799 0 ▶ method _build_eiffel ( $src, $out, $mode ) {
Subroutine _build_eiffel: not called CC=3 SCAR=24.8
800 0 ▶ my $se = $self->_can_run('se') // croak "SmartEiffel not found";
Condition0%0/2
$self->_can_run("se") // croak("SmartEiffel not found")
l!l
00
MC/DC0%0/1
$self->_can_run("se") // croak("SmartEiffel not found")
$self->_can_run("se")
Truth table0%0/2
A
A= $self->_can_run("se")
Aresult
11
00
801 0 ▶ my $file = ref $src ? $src->{path} : $src;
Branch: 1 branch
BranchTrueFalseTotal
ref $src ? : 0 0 0
802  
803 # Transpile to C
804 0 my $c_file = $build_dir->child( $self->_base($file) . '.c' );
805 0 $self->_run( $se, 'c', '-o', "$c_file", "$file" );
806  
807 # Reuse C builder
808 0 return $self->_build_c( $c_file, $out, $mode );
809 }
810 }
811 }
812 56 1;
813 __END__
« builder/Affix/Builder.pm ↑ Summary blib/lib/Affix/Platform/BSD.pm »