Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,14 @@
"2.2.5-1"
]
},
"eyalroz-printf": {
"dependency_names": [
"eyalroz-printf"
],
"versions": [
"6.2.0-1"
]
},
"facil": {
"dependency_names": [
"facil"
Expand Down
9 changes: 9 additions & 0 deletions subprojects/eyalroz-printf.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[wrap-file]
directory = printf-6.2.0
source_url = https://github.com/eyalroz/printf/archive/refs/tags/v6.2.0.zip
source_filename = eyalroz-printf-6.2.0.zip
source_hash = 42f40b07cf1012d7a69e2c34d44b118dc3a70530f3e2b591962cfe7a7c133fc7
patch_directory = eyalroz-printf

[provide]
dependency_names = eyalroz-printf
158 changes: 158 additions & 0 deletions subprojects/packagefiles/eyalroz-printf/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
project(
'eyalroz-printf',
'c',
'cpp',
license: 'MIT',
meson_version: '>=0.63.0',

Check notice on line 6 in subprojects/packagefiles/eyalroz-printf/meson.build

View workflow job for this annotation

GitHub Actions / Ubuntu (x86_64)

Minimum Meson version is 0.63.0

0.38.0: build_by_default arg in executable 0.42.0: implicit_include_directories arg in executable 0.43.0: compiler.get_supported_arguments 0.46.0: format arg in configure_file 0.47.0: dict 0.49.0: configure_file.configuration dictionary 0.50.0: include_directories kwarg of type string 0.53.0: Dictionary entry using non literal key 0.54.0: meson.override_dependency 0.63.0: c_std in subproject default_options
version: '6.2.0',
default_options: [
'b_staticpic=false',
'c_std=c99',
'default_library=static', # For shared support we need to somehow provide putchar_ implementation
'warning_level=3',
],
)


cc = meson.get_compiler('c')
## Checks related to the 'j', 'z' and 't' size modifiers
sizeof_long = cc.sizeof('long')
sizeof_long_long = cc.sizeof('long long')
acceptable_jzt_type_sizes = [sizeof_long, sizeof_long_long]
types = ['intmax_t', 'size_t', 'ptrdiff_t']
foreach type : types
type_size = cc.sizeof(
type,
prefix: '#include <stdint.h>',
)
if type_size not in acceptable_jzt_type_sizes
error(
f'sizeof(@type@) is @type_size@, which is neither sizeof(long) (@sizeof_long@) nor sizeof(long long) (@sizeof_long_long@). Please contact the library maintainers with your platform details.',
)
endif
endforeach

lib_config = {}
public_c_args = []
aliasing_defines = {
'hard': {
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_SOFT': 0,
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_HARD': 1,
},
'soft': {
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_SOFT': 1,
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_HARD': 0,
},
'none': {
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_SOFT': 0,
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_HARD': 0,
},
}
alias_standard_function_names = get_option('alias_standard_function_names')
if alias_standard_function_names != 'none'
option_val_upper = alias_standard_function_names.to_upper()
public_c_args += f'-DPRINTF_ALIAS_STANDARD_FUNCTION_NAMES_@option_val_upper@=1'
public_c_args += cc.get_supported_arguments('-fno-builtin-printf')
endif
lib_config += aliasing_defines[alias_standard_function_names]

bool_option_names = [
'support_decimal_specifiers',
'support_exponential_specifiers',
'support_msvc_style_integer_specifiers',
'support_writeback_specifier',
'support_long_long',
'use_double_internally',
'check_for_nul_in_format_specifier',
]
foreach option_name : bool_option_names
lib_config += {
'PRINTF_' + option_name.to_upper(): get_option(option_name).to_int(),
}
endforeach
int_option_names = ['integer_buffer_size', 'decimal_buffer_size']
foreach option_name : int_option_names
lib_config += {
'PRINTF_' + option_name.to_upper(): get_option(option_name),
}
endforeach
int_option_names_wo_prefix = [
'default_float_precision',
'max_integral_digits_for_decimal',
'log10_taylor_terms',
]
foreach option_name : int_option_names_wo_prefix
lib_config += {
option_name.to_upper(): get_option(option_name),
}
endforeach

cfg_header_file = configure_file(
input: 'printf_config.h.in',
configuration: lib_config,
format: 'cmake@',
output: 'printf_config.h',
)
eyalroz_printf_lib = library(
'eyalroz-printf',
'src/printf/printf.c',
cfg_header_file,
include_directories: 'src',
c_args: ['-DPRINTF_INCLUDE_CONFIG_H', public_c_args],
)
eyalroz_printf_dep = declare_dependency(
include_directories: 'src',
link_with: eyalroz_printf_lib,
compile_args: [public_c_args],
)
meson.override_dependency('eyalroz-printf', eyalroz_printf_dep)

subdir('test')

# Prints the sizes of the different sections of the ELF file: text, dat, vss etc.
size_prog = find_program(
'size',
required: false,
)
if size_prog.found()
custom_target(
'printf-sizes',
command: [size_prog, '-A', '-t', eyalroz_printf_lib],
capture: true,
output: 'printf_sizes.txt',
)
endif

# Produces lists of the symbols, and C++demangled symbols, inside the library
nm_prog = find_program(
'nm',
required: false,
)
if nm_prog.found()
custom_target(
'printf-symbols',
command: [nm_prog, '--numeric-sort', '--print-size', eyalroz_printf_lib],
capture: true,
output: 'printf_symbols.txt',
)
endif

# Dissassembles the compiled library into an .list file
objdump_prog = find_program(
'objdump',
required: false,
)
if objdump_prog.found()
custom_target(
'printf-lst',
command: [
objdump_prog,
'--disassemble',
'--line-numbers',
'-S',
eyalroz_printf_lib,
],
capture: true,
output: 'printf.list',
)
endif
85 changes: 85 additions & 0 deletions subprojects/packagefiles/eyalroz-printf/meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
option(
'test_with_non_standard_format_strings',
description: 'Include tests using non-standard-compliant format strings',
type: 'boolean',
)

option(
'support_decimal_specifiers',
description: 'Support decimal notation floating-point conversion specifiers (%f,%F)',
type: 'boolean',
)
option(
'support_exponential_specifiers',
description: 'Support exponential floating point format conversion specifiers (%e,%E,%g,%G)',
type: 'boolean',
)
option(
'support_writeback_specifier',
description: 'Support the length write-back specifier (%n)',
type: 'boolean',
)
option(
'support_msvc_style_integer_specifiers',
description: 'Support the I + bit size integer specifiers (%I8, %I16, %I32, %I64) as in Microsoft Visual C++',
type: 'boolean',
)
option(
'support_long_long',
description: 'Support long long integral types (allows for the ll length modifier and affects %p)',
type: 'boolean',
)
option(
'use_double_internally',
description: 'Use the C `double` type - typically 64-bit in size - for internal floating-point arithmetic',
type: 'boolean',
)
option(
'check_for_nul_in_format_specifier',
description: 'Be defensive in the undefined-behavior case of a format specifier not ending before the string ends',
type: 'boolean',
)

option(
'integer_buffer_size',
description: 'Integer to string conversion buffer size',
type: 'integer',
min: 0,
value: 32,
)
option(
'decimal_buffer_size',
description: 'Floating-point to decimal conversion buffer size',
type: 'integer',
min: 0,
value: 32,
)
option(
'default_float_precision',
description: 'Default precision when printing floating-point values',
type: 'integer',
min: 0,
value: 6,
)
option(
'max_integral_digits_for_decimal',
description: 'Maximum number of integral-part digits of a floating-point value for which printing with %f uses decimal (non-exponential) notation',
type: 'integer',
min: 0,
value: 9,
)
option(
'log10_taylor_terms',
description: 'The number of terms in a Taylor series expansion of log_10(x) to use for approximation',
type: 'integer',
min: 0,
value: 4,
)

option(
'alias_standard_function_names',
description: 'Alias the standard library function names (printf, sprintf etc.) to the library\'s functions - concretely, via a macro, or not at all',
type: 'combo',
choices: ['none', 'hard', 'soft'],
value: 'none',
)
64 changes: 64 additions & 0 deletions subprojects/packagefiles/eyalroz-printf/test/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
common_compiler_args = [
'-gdwarf-2',
'-ffunction-sections',
'-fdata-sections',
'-fverbose-asm',
'-Wundef',
'-Wshadow',
'-Wunreachable-code',
'-Wswitch-default',
'-Wcast-align',
'-Wmissing-include-dirs',
'-Winit-self',
'-Wdouble-promotion',
'-Wunused-parameter',
'-Wstrict-prototypes',
'-Wsign-conversion',
]

c_common_args = cc.get_supported_arguments(common_compiler_args)
c_common_args += cc.get_supported_arguments('-fno-builtin-printf')
aliasing_exe = executable(
'aliasing',
'aliasing.c',
cfg_header_file,
build_by_default: false,
c_args: c_common_args,
dependencies: [eyalroz_printf_dep],
include_directories: '..',
override_options: ['c_std=c11'],
)
test('printf.aliasing', aliasing_exe)

cxx = meson.get_compiler('cpp')
cxx_common_args = cxx.get_supported_arguments(common_compiler_args)
if get_option('test_with_non_standard_format_strings')
cxx_common_args += '-DTEST_WITH_NON_STANDARD_FORMAT_STRINGS'
endif
autotest_exe = executable(
'autotest',
'autotest.cpp',
cfg_header_file,
build_by_default: false,
cpp_args: cxx_common_args,
implicit_include_directories: false,
include_directories: '..',
dependencies: eyalroz_printf_dep,
override_options: ['cpp_std=c++11', 'cpp_eh=none'],
)
# Not running autotest by default - it's randomized after all.

# Ignore next test while 'test/test_suite_main_testcases.hpp:829' is not fixed in new version
#
# if get_option('alias_standard_function_names') != 'soft'
# test_suite_exe = executable(
# 'test_suite',
# 'test_suite.cpp',
# cfg_header_file,
# build_by_default: false,
# cpp_args: ['-DPRINTF_INCLUDE_CONFIG_H', cxx_common_args],
# include_directories: ['..', '../src'],
# override_options: ['cpp_std=c++11', 'cpp_eh=none'],
# )
# test('printf.test_suite', test_suite_exe)
# endif
Loading