Name

SPVM::Builder::API - Builder APIs

Description

SPVM::Builder::API class has the public methods to build SPVM native classes and SPVM precompilation classes.

Usage

my $builder = SPVM::Builder::API->new(
  build_dir => '.spvm_build',
);

$builder->build_dynamic_lib_dist_precompile('MyClass');

$builder->build_dynamic_lib_dist_native('MyClass');

Class Methods

new

my $builder = SPVM::Builder::API->new(%options);

Creates a new SPVM::Builder::API object, and returns it.

Options:

  • build_dir

    A build directory.

  • optimize

    The optimization level for the compiler.

Instance Methods

build_dynamic_lib_dist_precompile

$builder->build_dynamic_lib_dist_precompile($class_name)
$builder->build_dynamic_lib_dist_precompile($class_name, $options)

Generates a dynamic library for a native class given by the class name $class_name, and copies it into the blib/lib directory.

A native class must have at least one method with native attribute.

Options:

$options is a hash reference. This is optional.

  • optimize

    The optimization level for the compiler (e.g., O2, O3, O0).

build_dynamic_lib_dist_native

$builder->build_dynamic_lib_dist_native($class_name)
$builder->build_dynamic_lib_dist_native($class_name, $options)

Generates a dynamic library for a precompilation class $class_name that has native methods, and copies it into the blib/lib directory.

A precompilation class must have at least one method with precompile attribute.

Options:

$options is a hash reference. This is optional.

  • optimize

    The optimization level for the compiler (e.g., O2, O3, O0).

build_parallel_dynamic_lib_dist

$builder->build_parallel_dynamic_lib_dist($options);

Generates dynamic libraries for multiple native classes and precompile classes in parallel, and copies them into the blib/lib directory.

Options:

$options is a hash reference.

  • native_classes

    An array reference of native class names to be built.

  • native_classes_file

    A path to a text file containing native class names to be built. The file must contain one class name per line. If both native_classes and this option are specified, they are merged.

  • precompile_classes

    An array reference of precompile class names to be built.

  • precompile_classes_file

    A path to a text file containing precompile class names to be built. The file must contain one class name per line. If both precompile_classes and this option are specified, they are merged.

  • optimize

    The optimization level for the compiler (e.g., O2, O3, O0).

  • jobs

    The number of parallel jobs. The default value is the number of CPU cores.

  • build_type

    The build type for the compiler and linker. This option follows the standard CMake build types.

    Options:

    • Debug

      For debugging. Optimization is disabled and debug symbols are enabled.

    • Release

      For production. High optimization and no debug symbols.

    • RelWithDebInfo

      For production with debug symbols. High optimization with debug symbols.

    • MinSizeRel

      For production, optimized for binary size.

    If this option is specified, it overrides the optimize option and sets appropriate flags for both the compiler and the linker to match CMake's behavior.