ExtUtils-nvcc

 view release on metacpan or  search on metacpan

lib/ExtUtils/nvcc.pm  view on Meta::CPAN

# Parameters	: $mode, either 'compiler' or 'linker'
#				: @args, user-level arguments to MB, EUMM, and Inline
# Throws		: if a bade mode or an invalid option is provided
# Comments		: For example, an output of this function with no args could be
#				:    perl -MExtUtils::nvcc::Backend -e"ExtUtils::nvcc::Backend::linker" --
#				: This also checks for current use of blib and adds it if found
# See also		: verbosity, Inline, EUMM, MB, %args_for

sub build_args {
	my $mode = shift;
	croak("Bad mode; must be either 'compiler' or 'linker'")
		unless $mode eq 'compiler' or $mode eq 'linker';
	
	# Inject -Mblib if this script was invoked with blib:
	my $args = $^X;
	if (grep /blib/, @INC) {
		use Cwd;
		$args .= ' -Mblib="' . getcwd . '"';
	}
	

	# Go through and build the argument list, checking the arguments along the
	# way. If there are bad arguments, collect a full list and croak them all.

	$args .= qq{ -MExtUtils::nvcc::Backend -e"};
	my @bad_args;
	foreach (@_) {
		if (exists $arg_for{$_}) {
			$args .= $arg_for{$_} . ';';
		}
		else {
			push @bad_args, $_;
		}
	}
	croak('Bad arguments: ' . join(', ', @bad_args)) if @bad_args;
	return $args . qq{ExtUtils::nvcc::Backend::$mode" --};
}

1;

=head1 WINDOWS ISSUES

Windows usage presents a couple of difficulties, as described in this section.

=head2 Visual Studio Only

Unfortunately, nVidia's compiler wrapper (nvcc) only supports the use of cl.exe
on Windows. This means that Cygwin and Strawberry Perl users are out of luck for
using ExtUtils::nvcc. I attempted to install Visual Studio alongside Strawberry
Perl, but the Perl toolchain passes along the gcc flags, which cl.exe does not
like. There may be a way to fiddle with the configuration a bit, but I wouldn't
hold my breath.

An alternative may be to create a drop-in cl.exe replacement which parses the
arguments for cl.exe and invokes gcc. If that's not reverse-engineering
reverse-engineered, I don't know what is.

=head2 Visual Studio Command Prompt

When you install Visual Studio (as of Visual Studio 2010), you will get a Start
Menu entry for Visual Studio Command Prompt. You should run your build processes
(i.e. cpan) from one of these command prompts. Among other things, this command
prompt sets all of the necessary environment variables to ensure that the
compiler can be found, and that the compiler can find all the necessary
libraries. This may or may not be necessary for using nvcc directly, but it is
certainly is necessary for the rest of the Perl toolchain to find cl.exe and
friends.


=head1 DIAGNOSTICS

ExtUtils::nvcc could croak for a number of reasons. To keep things concise, I
list both the front-end and the back-end diagnostic messages here. I begin with
the front-end errors, errors that ExtUtils::nvcc will throw at you:

=over

=item Bad mode; must be either 'compiler' or 'linker'

This is an internal error that gets thrown when C<build_args> is called with
an invalid mode. If you see this, either you are C<build_args> yourself, and
not supplying the string 'compiler' or 'linker', or there is an internal error.
In the latter case, please report the error to the bug-tracker listed below.

=item Bad arguments: <bad-arg-1>, <bad-arg-2>, ...

This message means that you supplied an invalid argument to one of the
user-level functions C<Inline>, C<EUMM>, or C<MB>. Check your spelling and
capitalization against L</Optional Arguments> discussed above.

=back

These are the back-end errors, errors that L<ExtUtils::nvcc::Backend> will have:

=over

=item Last argument [[<arg>]] left me expecting a value, but I didn't find one

Apparently you (or the build system) supplied a list of arguments to
L<ExtUtils::nvcc::Backend> ending with an option that expects an argument.
For example, the C<-o> option is a very common option that indicates the output
filename from the compilation or linking process. If you supply a C<-o> option
to L<ExtUtils::nvcc::Backend>, it expects the following argument to be the
output filename. If this is your last argument and you don't supply a filename,
this error will be thrown.

If the last argument is complete, to the best of your knowledge, it could be
that L<ExtUtils::nvcc::Backend> mis-parsed your command-line arguments in other
ways. You should enable verbose output and study that for more details.

=item Nothing to do! You didn't give me any arguments, not even a file!

This means that you somehow invoked L<ExtUtils::nvcc::Backend> without a single
argument. Double-check your command-line invocation and try again.

=item You must provide at least one source file

Somehow you invoked L<ExtUtils::nvcc::Backend> without a source file listed.
Double-check your command-line invocation and try again.

=item Unable to run nvcc. Is it in your path?



( run in 1.457 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )