Name
SPVM::Builder::Config::Global - Excutable File Config
Description
The SPVM::Builder::Config::Global class has methods to manipulate the config for the excutable file generated by spvmcc command.
Usage
use SPVM::Builder::Config::Global;
my $config_global = SPVM::Builder::Config::Global->new;
Details
Warning: Should Not Change Compiler Flags
The fields for compiler flags in SPVM::Builder::Config such as "cc" in SPVM::Builder::Config, "std" in SPVM::Builder::Config should not be changed.
This is because the compiler flags are used to compile SPVM core source files and a bootstrap source file generagted by spvmcc command.
Super Class
Fields
before_compile_cbs
my $before_compile_cbs = $config_global->before_compile_cbs;
$config_global->before_compile_cbs($before_compile_cbs);
Gets and sets the before_compile_cbs field, an array reference of callbacks that work globally called just before the compile command "cc" is executed.
This affects all compilations.
optimize
$config->optimize($optimize, $condition);
Sets optimize field for the configs that match the condition $condition.
This method is a setter-only method. It calls "match" internally.
If $condition is not defined, the optimization setting is applied to all configs.
Examples:
# Set -O3 for all configs
$config->optimize('-O3');
# Set -O2 for native category configs
$config->optimize('-O2', {category => 'native'});
Methods
new
my $config_global = SPVM::Builder::Config::Global->new(%fields);
Create a new SPVM::Builder::Config::Global object with "Fields" and fields of its super classes.
This method calls the new method of its super class given %fields with field default values applied.
Field Default Values:
-
"exe" -
[] Other Fields
undef
add_before_compile_cb
$config_global->add_before_compile_cb(@before_compile_cbs);
Adds @before_compile_cbs to the end of "before_compile_cbs" field.
Examples:
$config_global->add_before_compile_cb(sub {
my ($config, $compile_info) = @_;
my $cc_command = $compile_info->to_command;
# Do something
});
compile_match
$global_config->compile_match($condition, $match_config_or_cb);
Adds a rule to dynamically update the configuration before compilation if the given conditions are met.
Parameters:
$conditionA hash reference or an SPVM::Builder::Config object specifying the match criteria. Each key represents a field name in the target configuration.
If the value is a
Regexpobject (e.g.,qr/.../), it performs a regex match.If the value is
undef, it matches if the target field is alsoundef.Otherwise, it performs a string equality check (
eq).
$match_config_or_cbA hash reference, an SPVM::Builder::Config object, or a code reference (callback).
If it is a hash reference or a config object, the fields in the target configuration are updated. You can use the
+prefix in the field name to append values instead of overwriting them:+field =$string> : Concatenates the string to the existing value.+field =$array_ref> : Pushes the elements of the array reference into the existing array. If the existing value is a scalar, it is promoted to an array before the push.
If it is a code reference, the callback is executed with the target SPVM::Builder::Config object as its first argument. This allows for complex, procedural updates to the configuration.
compile_match_any
$global_config->compile_match_any($match_config_or_cb);
A syntax sugar for "match" with no conditions. The $match_config will be applied to all configurations before compilation.
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License