Name
SPVM::Builder::Util::API - Builder Utility APIs
Description
The SPVM::Builder::Util::API module has the public utility functions to build SPVM native classes and SPVM precompilation classes.
Usage
my $native_make_rule = SPVM::Builder::Util::API::create_make_rule_native('MyClass');
my $precompile_make_rule = SPVM::Builder::Util::API::create_make_rule_precompile('MyClass');
Functions
create_make_rule_native
my $make_rule = SPVM::Builder::Util::API::create_make_rule_native($class_name, $options);
Creates a string of make commands for generating a dynamic library for a native class given the class name $class_name, and returns it.
A native class must have at least one method with native attribute.
$options is a hash reference. The available options are the same as those for "create_make_rule_parallel".
Note that the following option is automatically set:
native_classesThis option is automatically set to
[$class_name].
Examples:
# Makefile.PL
sub MY::postamble {
my $make_rule = '';
# Native compile make rule
$make_rule .= SPVM::Builder::Util::API::create_make_rule_native('Foo');
return $make_rule;
}
create_make_rule_precompile
my $make_rule = SPVM::Builder::Util::API::create_make_rule_precompile($class_name, $options);
Creates a string of make commands for generating a dynamic library for a precompilation class given the class name $class_name, and returns it.
A precompilation class must have at least one method with precompile attribute.
$options is a hash reference. The available options are the same as those for "create_make_rule_parallel".
Note that the following option is automatically set:
precompile_classesThis option is automatically set to
[$class_name].
Examples:
# Makefile.PL
sub MY::postamble {
my $make_rule = '';
# Precompile make rule
$make_rule .= SPVM::Builder::Util::API::create_make_rule_precompile('Foo');
return $make_rule;
}
create_default_config
my $config = SPVM::Builder::Util::API::create_default_config();
Creates a default config, and returns it. It is an SPVM::Builder::Config object.
Currently the default config is created by the following operation.
my $config = SPVM::Builder::Config->new_c99;
get_cpu_count
my $cpu_count = SPVM::Builder::Util::API::get_cpu_count();
Returns the number of CPU cores on the current system.
This function detects the available CPU count in a platform-independent way (Windows, Linux, macOS, etc.).
If the CPU count cannot be determined, it returns 1.
create_make_rule_parallel
my $make_rule = SPVM::Builder::Util::API::create_make_rule_parallel($options);
Creates a string of make commands for generating dynamic libraries for multiple native classes and precompile classes in parallel, and returns it.
$options is a hash reference.
Options:
The following options are the same as those for "build_parallel_dynamic_lib_dist" in SPVM::Builder::API:
native_classesprecompile_classesbuild_fileforceoptimizejobs
The following options are specific to this method:
dependent_filesAn array reference of dependency file paths for the
maketarget. These files are treated as normal dependencies.$options->{dependent_files} = ['SPVM.xs'];order_only_dependent_filesAn array reference of order-only dependency file paths for the
maketarget. These files must exist before the target is built, but their modification times do not trigger a rebuild.$options->{order_only_dependent_files} = ['$(INST_DYNAMIC)'];
Examples:
# Makefile.PL
sub MY::postamble {
my $make_rule = '';
# Parallel build make rule
$make_rule .= SPVM::Builder::Util::API::create_make_rule_parallel({
native_classes => [
'Foo',
'Bar',
],
precompile_classes => [
'Baz',
],
optimize => 'O3',
dependent_files => ['SPVM.xs'],
order_only_dependent_files => ['$(INST_DYNAMIC)'],
});
return $make_rule;
}
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License