SPVM::B...::Config(3)

πŸ“¦ version 0.990125, in alpine 3.24

πŸŽ€ NAME πŸŽ€

SPVM::B...::Config(3) β€” User Contributed Perl Documentation β€” okay so the actual class is SPVM::Builder::Config, and it’s literally the config for compiling and linking native classes. πŸ’…

πŸ’– DESCRIPTION πŸ’–

The SPVM::Builder::Config class has methods to get and set config for compiling and linking native classes. It’s giving β€œbackstage pass to the build system,” and honestly? Iconic. ✨

πŸ› οΈ USAGE πŸ› οΈ

Okay bestie, here’s the whole vibe in code form β€” every line stays exactly as it should:

use SPVM::Builder::Config;

# Create a config
my $config = SPVM::Builder::Config->new(file => __FILE__);

# GNU C99
my $config = SPVM::Builder::Config->new_gnu99(file => __FILE__);

# C99
my $config = SPVM::Builder::Config->new_c99(file => __FILE__);

# C++
my $config = SPVM::Builder::Config->new_cpp(file => __FILE__);

# C++11
my $config = SPVM::Builder::Config->new_cpp11(file => __FILE__);

# C++17
my $config = SPVM::Builder::Config->new_cpp17(file => __FILE__);

# Optimize
$config->optimize("-O2");

# Optimize with debug mode
$config->optimize("-O0 -g");

# Add ccflags
$config->add_ccflag("-DFOO");

$config->add_define("FOO");

# Add source files
$config->add_source_file("foo.c", "bar.c", "baz/baz.c");

# Add libraries
$config->add_lib("gdi32", "d2d1", "Dwrite");

# Add ldflags
$config->add_ldflag("-pthread");

# Use resource
$config->use_resource("Resource::MyResource");

πŸ’… FIELDS πŸ’…

πŸ¦‹ ext

my $ext = $config->ext;
$config->ext($ext);

Gets and sets the ext field: the extension of a native class. Cute little file-suffix moment. πŸ’–

Examples:

# MyClass.c
$config->ext('c');

# MyClass.cpp
$config->ext('cpp');

# MyClass.cc
$config->ext('cc');

# MyClass.cu
$config->ext('cu');

# MyClass.m
$config->ext('m');

🌸 cc

my $cc = $config->cc;
$config->cc($cc);

Gets and sets the cc field: a compiler name. The main-character compiler, basically. πŸ‘‘

Examples:

# gcc
$config->cc('gcc');

# g++ for C++
$config->cc('g++');

# nvcc for CUDA/GUP
$config->cc('nvcc');

# cc that compiled this Perl
use Config;
$config->cc($Config{cc});

πŸŽ€ include_dirs

my $include_dirs = $config->include_dirs;
$config->include_dirs($include_dirs);

Gets and sets the include_dirs field: an array reference containing header file search directories.

The values of this field are converted to -I options when the arguments of the compiler cc are created.

# -I /path1 -I /path2
$config->include_dirs(['/path1', '/path2']);

🧚 spvm_core_include_dir

my $spvm_core_include_dir = $config->spvm_core_include_dir;
$config->spvm_core_include_dir($spvm_core_include_dir);

Gets and sets the spvm_core_include_dir field: an SPVM core header file search directory.

The value of this field is converted to -I option when the arguments of the compiler cc are created.

This field is automatically set and users normally do not change it. ✨

πŸ¦‹ native_include_dir

my $native_include_dir = $config->native_include_dir;
$config->native_include_dir($native_include_dir);

Gets and sets the native_include_dir field: a native header file search directory.

The value of this field is converted to -I option when the arguments of the compiler cc are created.

This field is automatically set and users normally do not change it. πŸ’«

🌈 native_src_dir

my $native_src_dir = $config->native_src_dir;
$config->native_src_dir($native_src_dir);

Gets and sets the native_src_dir field: a native source file search directory.

This field is automatically set and users normally do not change it. 🫢

πŸ’œ ccflags

my $ccflags = $config->ccflags;
$config->ccflags($ccflags);

Gets and sets the ccflags field: an array reference containing arguments of the compiler cc. Yes, the compiler’s little accessory bag. πŸŽ€

πŸ”₯ defines

my $defines = $config->defines;
$config->defines($defines);

Gets and sets the defines field: an array reference containing the values of -D arguments of the compiler cc.

⭐ optimize

my $optimize = $config->optimize;
$config->optimize($optimize);

Gets and sets the optimize field: an argument of the compiler cc for optimization. Make it fast, make it cute, make it compile. πŸ’…

Examples:

$config->optimize('-O3');
$config->optimize('-O2');
$config->optimize('-g3 -O0');

πŸ“ dynamic_lib_ccflags

my $dynamic_lib_ccflags = $config->dynamic_lib_ccflags;
$config->dynamic_lib_ccflags($dynamic_lib_ccflags);

Gets and sets the dynamic_lib_ccflags field: an array reference containing arguments of the compiler cc for dynamic linking.

This field is automatically set and users normally do not change it. πŸ’–

🧡 thread_ccflags

my $thread_ccflags = $config->thread_ccflags;
$config->thread_ccflags($thread_ccflags);

Gets and sets the thread_ccflags field: an array reference containing arguments of the compiler cc for threads.

This field is automatically set and users normally do not change it. 🧚

πŸͺŸ mingw_ccflags

my $mingw_ccflags = $config->mingw_ccflags;
$config->mingw_ccflags($mingw_ccflags);

Gets and sets the mingw_ccflags field: an array reference containing arguments of the compiler cc for MinGW.

This field is automatically set and users normally do not change it. ✨

🎯 std

my $std = $config->std;
$config->std($std);

Gets and sets the std field: a language standard.

This field is converted to -std option when the arguments of the compiler cc are created.

Examples:

# -std=c99
$config->std('c99');

# -std=gnu99
$config->std('gnu99');

# -std=cpp
$config->std('cpp');

# -std=cpp11
$config->std('cpp11');

# -std=cpp17
$config->std('cpp17');

πŸ“ source_files

my $source_files = $config->source_files;
$config->source_files($source_files);

Gets and sets the source_files field: an array reference containing relative paths of native source files from the native_src_dir field.

🌟 before_compile_cbs

my $before_compile_cbs = $config->before_compile_cbs;
$config->before_compile_cbs($before_compile_cbs);

Gets and sets the before_compile_cbs field: an array reference containing callbacks called just before the compile command cc is executed.

These callbacks are executed only if an object file is actually generated.

The 1th argument of the callback is an SPVM::Builder::Config object.

The 2th argument of the callback is an SPVM::Builder::CompileInfo object.

πŸ”— ld

my $ld = $config->ld;
$config->ld($ld);

Gets and sets the ld field: a linker name.

Examples:

$config->ld('gcc');
$config->ld('g++');

πŸ“š lib_dirs

my $lib_dirs = $config->lib_dirs;
$config->lib_dirs($lib_dirs);

Gets and sets the lib_dirs field: an array reference containing library search directories.

The values of this field are converted to -L options when the arguments of the linker ld are created.

# -L /path1 -L /path2
$config->lib_dirs(['/path1', '/path2']);

🧸 libs

my $libs = $config->libs;
$config->libs($libs);

Gets and sets the libs field: an array reference containing library names such as z, and png or SPVM::Builder::LibInfo objects.

The values of this field are converted to -l options when the arguments of the linker ld are created.

See β€œLibrary Path Resolution” about resolving library paths.

Examples:

# -l libz -l libpng
$config->libs(['z', 'png']);

🌈 ldflags

my ldflags = $config->ldflags;
$config->ldflags(ldflags);

Gets and sets the ldflags field: an array reference containing arguments of the linker ld.

πŸ’« dynamic_lib_ldflags

my dynamic_lib_ldflags = $config->dynamic_lib_ldflags;
$config->dynamic_lib_ldflags(dynamic_lib_ldflags);

Gets and sets the dynamic_lib_ldflags field: an array reference containing arguments of the linker ld for dynamic libraries.

This field is automatically set and users normally do not change it. πŸ’–

🧡 thread_ldflags

my thread_ldflags = $config->thread_ldflags;
$config->thread_ldflags(thread_ldflags);

Gets and sets the thread_ldflags field: an array reference containing arguments of the linker ld for threads.

This field is automatically set and users normally do not change it. 🫢

🧱 static_lib_ldflag

my static_lib_ldflag = $config->static_lib_ldflag;
$config->static_lib_ldflag(static_lib_ldflag);

Gets and sets the static_lib_ldflag field: an array reference containing a pair of arguments to start statically linking and end it.

The library name added by the add_static_lib are surrounded by the values of the pair.

# -Wl,-Bstatic -llibfoo -Wl,-Bdynamic
$config->static_lib_ldflag(['-Wl,-Bstatic', '-Wl,-Bdynamic']);
$config->add_static_lib('foo');

This field is automatically set and users normally do not change it.

⚠️ This field only works correctly in Linux/Unix.

Mac does not support these options. If you want to search a static library, create a new library search directory, copy a static library to there, and add the new library search directory.

# /path_for_static_lib/libz.a
$config->add_lib_dir('/path_for_static_lib');
$config->add_lib('z');

MinGW on Windows supports these options, but instead of linking statically, it links dynamically with absolute paths. This is usually not the intended behavior. If you want to do static linking on Windows, you need to use -static option. πŸ’€

⚑ ld_optimize

my $ld_optimize = $config->ld_optimize;
$config->ld_optimize($ld_optimize);

Gets and sets the ld_optimize field: an argument of the linker ld for optimization.

Examples:

$config->ld_optimize("-O3");
my $before_link_cbs = $config->before_link_cbs;
$config->before_link_cbs($before_link_cbs);

Gets and sets the before_link_cbs field: an array reference containing callbacks called just before the link command ld is executed.

These callbacks are executed only if a dynamic link library is actually generated.

The 1th argument of the callback is an SPVM::Builder::Config object.

The 2th argument of the callback is an SPVM::Builder::LinkInfo object.

🚨 force

my $force = $config->force;
$config->force($force);

Gets and sets the force field.

If this field is a true value, the compilation and linking are forced.

If this field is a false value except for undef, the compilation and linking are performed following the rule of the dependency resolution.

If this field is undef, this config does not specify whether the compilation and linking are performed.

🀫 quiet

my $quiet = $config->quiet;
$config->quiet($quiet);

Gets and sets the quiet field.

If this field is a true value, the messages from the compiler and the linker are output to stderr.

If this field is a false value except for undef, the messages from the compiler and the linker are not output.

If this field is undef, this config does specify whether the messages from the compiler and the linker are output.

πŸ¦‹ class_name

my $class_name = $config->class_name;
$config->class_name($class_name);

Gets and sets the class_name field β€” literally the name of the class this config is configuring. It gets auto-set for you, so bestie you normally do not need to touch it. πŸ’…

πŸŽ€ file

my $file = $config->file;
$config->file($file);

Gets and sets the file field, aka the file path of this config. This one is set by the load_config method, and users should not set it. No cap, leave it alone. 🫢

✨ output_type

my $output_type = $config->output_type;
$config->output_type($output_type);

Gets and sets the output_type field, which is the type of the output file output_file that the linker ld generates.

  • If this field is dynamic_lib, the output file is a dynamic link library.
  • If this field is static_lib, the output file is a static link library.
  • If this field is exe, the output file is an executable file.

This field is automatically set, and users normally do not change it. πŸ’–

🌸 resource_loader_config

my $resource_loader_config = $config->resource_loader_config;
$config->resource_loader_config($resource_loader_config);

Gets and sets the resource_loader_config field β€” the config file of the class that loaded a resource by the use_resource method. Auto-set, bestie, so you normally don't change it. 🧚

πŸ’œ category

my $category = $config->category;
$config->category($category);

Gets and sets the category field.

  • If this field is precompile, this config is for precompilation.
  • If this field is native, this config is for a native class.

This field is automatically set, and users normally do not change it. πŸ‘‘

πŸ”₯ config_exe

my $config_exe = $config->config_exe;
$config->config_exe($config_exe);

Gets and sets the config_exe field.

If the spvmcc command generates an executable file, this field is set to an SPVM::Builder::Config::Exe object.

This field is automatically set, and users normally do not change it. ⭐

πŸ¦‹ cc_input_dir

my $cc_input_dir = $config->cc_input_dir;
$config->cc_input_dir($cc_input_dir);

Gets and sets the cc_input_dir field β€” an input directory for the compiler cc. Auto-set, so users normally do not change it. πŸ’…

🌈 cc_output_dir

my $cc_output_dir = $config->cc_output_dir;
$config->cc_output_dir($cc_output_dir);

Gets and sets the cc_output_dir field β€” an output directory for the compiler cc. Auto-set, so users normally do not change it. ✨

πŸ“ output_dir

my $output_dir = $config->output_dir;
$config->output_dir($output_dir);

Gets and sets the output_dir field β€” an output directory for the linker ld. Auto-set, so users normally do not change it. πŸŽ€

πŸ’– output_file

my $output_file = $config->output_file;
$config->output_file($output_file);

Gets and sets the output_file field β€” a path of a dynamic link library or an executable file generated by the linker ld. Auto-set, so users normally do not change it. 🫢

πŸ¦‹ is_resource

my $is_resource = $config->is_resource;
$config->is_resource($is_resource);

Gets and sets the is_resource field.

If this field is true, this config is for a resource class. πŸ’œ


πŸ‘‘ Class Methods πŸ‘‘

✨ new

my $config = SPVM::Builder::Config->new(%fields);

Creates a new SPVM::Builder::Config object with fields, and returns it. Iconic constructor behavior, honestly. πŸ’…

Field Default Values β€” yes, all of them:

  • file
    • This value is set automatically.
  • cc
    • The $Config{cc} of Config module.
  • ccflags
    • []
  • defines
    • []
  • optimize
    • "-O3"
  • dynamic_lib_ccflags
    • Windows:
      • []
    • Other OSs:
      • ["-fPIC"]
  • thread_ccflags
    • Windows:
      • []
    • Other OSs:
      • ["-pthread"]
  • mingw_ccflags
    • Windows:
      • ['-D__USE_MINGW_ANSI_STDIO']
    • Other OSs:
      • []
  • include_dirs
    • []
  • spvm_core_include_dir
    • The SPVM core header file search directory.
  • native_include_dir
    • The directory described in "Native Header Files" in SPVM::Document::NativeClass.
    • Examples:
      • MyClass.naitve/include
  • native_src_dir
    • The directory described in "Native Source Files" in SPVM::Document::NativeClass.
    • Examples:
      • MyClass.naitve/src
  • source_files
    • []
  • before_compile_cbs
    • []
  • ld
    • The $Config{ld} of Config module.
  • ldflags
    • []
  • dynamic_lib_ldflags
    • Windows:
      • ["-mdll", "-s"]
    • Other OSs:
      • ["-shared"]
  • thread_ldflags
    • Windows:
      • []
    • Other OSs:
      • ["-pthread"]
  • static_lib_ldflag
    • ["-Wl,-Bstatic", "-Wl,-Bdynamic"]
  • ld_optimize
    • "-O2"
  • lib_dirs
    • []
  • libs
    • []
  • before_link_cbs
    • []
  • output_type
    • "dynamic_lib"
  • category
    • "native"
  • Other Fields
    • undef

🌸 new_c

my $config = SPVM::Builder::Config->new_c(file => __FILE__);

Calls the new method and sets the ext field to c, then returns the return value of the new method. Slay, C files. πŸŽ€

🧚 new_gnu99

my $config = SPVM::Builder::Config->new_gnu99(file => __FILE__);

Calls the new_c method and sets the std field to gnu99, then returns the return value of the new_c method. πŸ’–

⭐ new_gnu11

my $config = SPVM::Builder::Config->new_gnu11(file => __FILE__);

Calls the new_c method and sets the std field to gnu11, then returns the return value of the new_c method. ✨

πŸ¦‹ new_c99

my $config = SPVM::Builder::Config->new_c99(file => __FILE__);

Calls the new_c method and sets the std field to c99, then returns the return value of the new_c method. πŸ’…

πŸ”₯ new_c11

my $config = SPVM::Builder::Config->new_c11(file => __FILE__);

Calls the new_c method and sets the std field to c11, then returns the return value of the new_c method. 🌈

πŸ’œ new_cpp

my $config = SPVM::Builder::Config->new_cpp(file => __FILE__);

Calls the new method and sets the ext field to cpp, sets the cc field to a C++ compiler, and sets the ld field to a C++ linker, then returns the return value of the new method.

If $Config{gccversion} contains clang, the cc field and ld field are set to clang++. Otherwise, the cc field and ld field are set to g++. Bestie, compiler drama handled. 🫢

🌸 new_cpp11

my $config = SPVM::Builder::Config->new_cpp11(file => __FILE__);

Calls the new_cpp method and sets the std field to c++11, then returns the return value of the new_cpp method. πŸŽ€

πŸ¦‹ new_cpp14

my $config = SPVM::Builder::Config->new_cpp14(file => __FILE__);

Calls the new_cpp method and sets the std field to c++14, then returns the return value of the new_cpp method. πŸ’–

✨ new_cpp17

my $config = SPVM::Builder::Config->new_cpp17(file => __FILE__);

Calls the new_cpp method and sets the std field to c++17, then returns the return value of the new_cpp method. πŸ‘‘

πŸ’… INSTANCE METHODS πŸ’…

Okay bestie, these are the methods you call on a SPVM::Builder::Config object. One by one, no cap. πŸ’–

πŸŽ€ add_ccflag

$config->add_ccflag(@ccflags);

Adds @ccflags to the end of the ccflags field. Slay.

πŸŽ€ add_define

$config->add_define(@defines);

Adds @defines to the end of the defines field. Periodt.

πŸŽ€ add_ldflag

$config->add_ldflag(@ldflags);

Adds @ldflags to the end of the ldflags field. πŸ’…

πŸŽ€ add_include_dir

$config->add_include_dir(@include_dirs);

Adds @include_dirs to the end of the include_dirs field. Iconic.

πŸŽ€ add_source_file

$config->add_source_file(@source_files);

Adds @source_files to the end of the source_files field.

Examples:

$config->add_source_file('foo.c', 'bar.c');

πŸŽ€ add_before_compile_cb

$config->add_before_compile_cb(@before_compile_cbs);

Adds @before_compile_cbs to the end of the before_compile_cbs field.

Examples:

$config->add_before_compile_cb(sub {
  my ($config, $compile_info) = @_;

  my $cc_command = $compile_info->to_command;

  # Do something
});

πŸŽ€ add_lib_dir

$config->add_lib_dir(@lib_dirs);

Adds @lib_dirs to the end of the lib_dirs field. Obsessed.

πŸŽ€ add_lib

$config->add_lib(@libs);

Adds @libs to the end of the libs field.

Examples:

$config->add_lib('gsl');
$config->add_lib('gsl', 'z');
$config->add_lib(
  SPVM::Builder::LibInfo->new(config => $config, name => 'gsl'),
  SPVM::Builder::LibInfo->new(config => $config, name => 'z', is_abs => 1),
);

πŸŽ€ add_lib_abs

$config->add_lib_abs(@libs);

Adds @libs to the end of the libs field with the SPVM::Builder::LibInfo#is_abs field set to a true value.

If a value in @libs is not an SPVM::Builder::LibInfo object, an SPVM::Builder::LibInfo object is created from the library name.

If the library is located in your user directory, it is good to use the add_lib_abs method instead of the add_lib method.

This is because if the generated dynamic link library has a relative path, that path cannot be resolved when it is loaded.

For system libraries, there is no problem because the linker knows the search directory for the library. So that part is chill. πŸ¦‹

πŸŽ€ add_static_lib

$config->add_static_lib(@libs);

Adds @libs to the end of the libs field with the SPVM::Builder::LibInfo#is_static field set to a true value.

If a value in @libs is not an SPVM::Builder::LibInfo object, an SPVM::Builder::LibInfo object is created from the library name.

Examples:

$config->add_static_lib('gsl');
$config->add_static_lib('gsl', 'z');

πŸŽ€ add_static_lib_abs

$config->add_static_lib_abs(@libs);

Adds @libs to the end of the libs field with the SPVM::Builder::LibInfo#is_static field and the SPVM::Builder::LibInfo#is_abs field set to a true value.

If a value in @libs is not an SPVM::Builder::LibInfo object, an SPVM::Builder::LibInfo object is created from the library name. Main character energy. πŸ‘‘

$config->add_before_link_cb(@before_link_cbs);

Adds @before_link_cbs to the end of the before_link_cbs field.

Examples:

$config->add_before_link_cb(sub {
  my ($config, $link_info) = @_;

  my $object_files = $link_info->object_files;

  # Do something

});

πŸŽ€ use_resource

my $resource = $config->use_resource($resource_name);
my $resource = $config->use_resource($resource_name, %options);

Loads a resource given a resource class name, and returns it. The return value is an SPVM::Builder::Resource object.

Examples:

$config->use_resource('Resource::MyResource');

πŸŽ€ get_resource

my $resource = $config->get_resource($resource_name);

Gets a resource loaded by the use_resource method given a resource name, and returns it. The return value is an SPVM::Builder::Resource object.

πŸŽ€ get_resource_names

my $resource_names = $config->get_resource_names;

Returns resource names loaded by the use_resource method. Iykyk. πŸ’œ

πŸŽ€ load_config

my $config = $config->load_config($config_file);

Loads a config file given a config file path and an array reference containing config arguments, and returns an SPVM::Builder::Config object.

Examples:

my $config = $config->load_config(__FILE__);

πŸŽ€ get_loaded_config_files

Returns the config files loaded by the load_config method. That's it, bestie. ✨

πŸŽ€ clone

my $clone = $self->clone;

Clones an SPVM::Builder::Config object, and returns it. Dupe era. πŸŽ€


🧚 LIBRARY PATH RESOLUTION 🧚

The following is the rule of library path resolution, and yes, this is important. Ngl, pay attention.

Library names are converted to SPVM::Builder::LibInfo objects.

If the SPVM::Builder::LibInfo#is_abs field is a false value, the linker ld resolves library paths.

If the SPVM::Builder::LibInfo#is_abs field is a true value, library paths are resolved by the following rules:

  • A library is searched in the library search directories contained in the lib_dir field from the beginning.
  • If the SPVM::Builder::LibInfo#is_static field is a false value, the search is performed in the order of a dynamic library, a static library.
  • If the SPVM::Builder::LibInfo#is_static field is a true value, the search is performed only in static libraries.
  • If a library is found, the -l option of the linker ld is created using the found absolute path.

Vibe check passed. 🌈


πŸ”₯ EXAMPLES πŸ”₯

GNU C99:

my $config = SPVM::Builder::Config->new_gnu99(file => __FILE__);

C99:

my $config = SPVM::Builder::Config->new_c99(file => __FILE__);

C11:

my $config = SPVM::Builder::Config->new_c11(file => __FILE__);

C++:

my $config = SPVM::Builder::Config->new_cpp(file => __FILE__);

C++11:

my $config = SPVM::Builder::Config->new_cpp11(file => __FILE__);

Output messages to stderr from the compiler and the linker:

$config->quiet(0);

Force the compilation and link:

$config->force(1);

Literally iconic examples. πŸ’…


Copyright (c) 2023 Yuki Kimoto

MIT License


πŸ’– That’s the whole vibe, bestie. This page is from perl v5.42.2, dated 2026-02-03, and it’s literally SPVM::B...::Config(3) β€” periodt. 🫢

πŸ“¦ where this page comes from