Skip Menu |

This queue is for tickets about the Module-Build CPAN distribution.

Report information
The Basics
Id: 59721
Status: stalled
Priority: 0/
Queue: Module-Build

People
Owner: Nobody in particular
Requestors: dagolden [...] cpan.org
Cc: rehsack [...] googlemail.com
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



CC: rehsack [...] googlemail.com
Subject: [PATCH] Compile C++ with new features of ExtUtils::CBuilder 0.27_04
Submitted by Jens Rehsack. I would like to have tests for this patch before committing it. -- David
Subject: patch-use-cxx-to-compile-c++-source.patch
Index: lib/Module/Build/Base.pm =================================================================== --- lib/Module/Build/Base.pm (revision 13899) +++ lib/Module/Build/Base.pm (working copy) @@ -2728,20 +2728,32 @@ my $p = $self->{properties}; return unless $p->{c_source}; - my $files; + my $cfiles; + my $cxxfiles; if (ref($p->{c_source}) eq "ARRAY") { push @{$p->{include_dirs}}, @{$p->{c_source}}; for my $path (@{$p->{c_source}}) { - push @$files, @{ $self->rscan_dir($path, file_qr('\.c(c|p|pp|xx|\+\+)?$')) }; + push @$cfiles, @{ $self->rscan_dir($path, file_qr('\.c$')) }; + push @cxx$files, @{ $self->rscan_dir($path, file_qr('\.c(c|p|pp|xx|\+\+)$')) }; + unless( $self->{fs_ignore_case} } ) { + push @cxx$files, @{ $self->rscan_dir($path, file_qr('\.C(C|P|PP|XX|\+\+)?$')) }; + } } } else { push @{$p->{include_dirs}}, $p->{c_source}; - $files = $self->rscan_dir($p->{c_source}, file_qr('\.c(c|p|pp|xx|\+\+)?$')); + $cfiles = $self->rscan_dir($p->{c_source}, file_qr('\.c(c|p|pp|xx|\+\+)?$')); + $cxxfiles = $self->rscan_dir($p->{c_source}, file_qr('\.c(c|p|pp|xx|\+\+)?$')); + unless( $self->{fs_ignore_case} } ) { + push @cxx$files, @{ $self->rscan_dir($path, file_qr('\.C(C|P|PP|XX|\+\+)?$')) }; + } } - foreach my $file (@$files) { + foreach my $file (@$cfiles) { push @{$p->{objects}}, $self->compile_c($file); } + foreach my $file (@$cxxfiles) { + push @{$p->{objects}}, $self->compile_cxx($file); + } } sub process_share_dir_files { @@ -4909,18 +4921,31 @@ my $p = $self->{properties}; return $p->{_have_c_compiler} if defined $p->{_have_c_compiler}; - $self->log_verbose("Checking if compiler tools configured... "); + $self->log_verbose("Checking if c compiler tools configured... "); my $b = eval { $self->cbuilder }; my $have = $b && eval { $b->have_compiler }; $self->log_verbose($have ? "ok.\n" : "failed.\n"); return $p->{_have_c_compiler} = $have; } +sub have_cxx_compiler { + my ($self) = @_; + + my $p = $self->{properties}; + return $p->{_have_cxx_compiler} if defined $p->{_have_cxx_compiler}; + + $self->log_verbose("Checking if c++ compiler tools configured... "); + my $b = eval { $self->cbuilder }; + my $have = $b && eval { $b->have_cplusplus }; + $self->log_verbose($have ? "ok.\n" : "failed.\n"); + return $p->{_have_cxx_compiler} = $have; +} + sub compile_c { my ($self, $file, %args) = @_; if ( ! $self->have_c_compiler ) { - die "Error: no compiler detected to compile '$file'. Aborting\n"; + die "Error: no c compiler detected to compile '$file'. Aborting\n"; } my $b = $self->cbuilder; @@ -4938,6 +4963,29 @@ return $obj_file; } +sub compile_cxx { + my ($self, $file, %args) = @_; + + if ( ! $self->have_cxx_compiler ) { + die "Error: no c++ compiler detected to compile '$file'. Aborting\n"; + } + + my $b = $self->cbuilder; + my $obj_file = $b->object_file($file); + $self->add_to_cleanup($obj_file); + return $obj_file if $self->up_to_date($file, $obj_file); + + $b->compile(source => $file, + defines => $args{defines}, + object_file => $obj_file, + include_dirs => $self->include_dirs, + extra_compiler_flags => $self->extra_compiler_flags, + 'C++' => 1, + ); + + return $obj_file; +} + sub link_c { my ($self, $spec) = @_; my $p = $self->{properties}; # For convenience @@ -4961,6 +5009,10 @@ return $spec->{lib_file}; } +sub link_cxx { + goto &link_c; +} + sub compile_xs { my ($self, $file, %args) = @_;
<[Sno]> maybe next week <@xdg> EU::CB has crappy test coverage so I'm happy to patch and pray <@xdg> M::B has better coverage and I don't want to put in anything that major without some tests <[Sno]> I have to finish a lot things around DBD::Sys until FrOSCon ;) <[Sno]> xdg: is there at least a compiler test in M::B? * leont (~leon@haar107.athome224.wau.nl) has joined #toolchain <[Sno]> which I could modify/enhance <@xdg> Sno|, there t/xs.t <@xdg> also t/properties/needs_compiler.t <[Sno]> I think I run the tests before I send the patch, but I'm not sure <[Sno]> I take a look at both * chorny (~chatzilla@host-static-92-115-75-35.moldtelecom.md) has joined #toolchain * GumbyNET3 gives channel operator status to chorny <@xdg> The "c_source" parameter may not be tested at all. <@xdg> You might want to actually write a new t/properties/c_source and do a test of both C and C++ <@xdg> Read the pod for t/lib/DistGen.pm