Skip to content

eyalroz-printf: Add new wrap v6.2.0 #2258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions subprojects/eyalroz-printf.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[wrap-file]
directory = eyalroz-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
lead_directory_missing = true

[provide]
dependency_names = eyalroz-printf
15 changes: 15 additions & 0 deletions subprojects/packagefiles/eyalroz-printf/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
project(
'eyalroz-printf',
'c',
'cpp',
license: 'MIT',
meson_version: '>=1.0.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 1.0.0

0.46.0: format arg in configure_file 0.47.0: dict 0.49.0: compiler.get_argument_syntax_method, 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 1.0.0: "compiler.sizeof" keyword argument "prefix" of type list
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
],
)

subdir('printf-6.2.0')
91 changes: 91 additions & 0 deletions subprojects/packagefiles/eyalroz-printf/meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
option(
'tests',
description: 'Build test programs for the library',
type: 'boolean',
value: false,
)
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',
)
151 changes: 151 additions & 0 deletions subprojects/packagefiles/eyalroz-printf/printf-6.2.0/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
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

private_c_args = []
public_c_args = []
lib_config = {}
if cc.get_argument_syntax() == 'gcc'
private_c_args += ['-Wall', '-Wextra', '-pedantic', '-Wconversion']
elif cc.get_argument_syntax() == 'msvc'
private_c_args += '/W4'
endif
if get_option('alias_standard_function_names') != 'none'
option_val_upper = get_option('alias_standard_function_names').to_upper()
public_c_args += f'-DPRINTF_ALIAS_STANDARD_FUNCTION_NAMES_@option_val_upper@=1'
if cc.get_argument_syntax() == 'gcc'
public_c_args += '-fno-builtin-printf'
endif

if get_option('alias_standard_function_names') == 'hard'
lib_config += {
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_SOFT': 0,
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_HARD': 1,
}
else
lib_config += {
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_SOFT': 1,
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_HARD': 0,
}
endif
else
lib_config += {
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_SOFT': 0,
'PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_HARD': 0,
}
endif
private_c_args += '-DPRINTF_INCLUDE_CONFIG_H'

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: [private_c_args, 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)

if get_option('tests')
subdir('test')
endif

# Prints the sizes of the different sections of the ELF file: text, dat, vss etc.
size_prog = find_program('size')
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')
if nm_prog.found()
lib_path = eyalroz_printf_lib.full_path()
sh_cmd = 'nm --numeric-sort --print-size ' + lib_path + ' > @OUTDIR@/printf_symbols.txt'
filt_prog = find_program('c++filt')
if filt_prog.found()
sh_cmd += ' && nm --numeric-sort ' + lib_path + ' | c++filt > @OUTDIR@/printf_cpp_symbols.txt'
endif
custom_target(
'printf-symbols',
command: ['sh', '-c', sh_cmd],
depends: eyalroz_printf_lib,
output: ['printf_symbols.txt', 'printf_cpp_symbols.txt'],
)
endif

# Dissassembles the compiled library into an .list file
objdump_prog = find_program('objdump')
if objdump_prog.found()
custom_target(
'printf-lst',
command: [
objdump_prog,
'--disassemble',
'--line-numbers',
'-S',
eyalroz_printf_lib,
],
capture: true,
output: 'printf.list',
)
endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
common_msvc_args = ['/W4']
common_gcc_args = [
'-g',
'-Wall',
'-Wextra',
'-pedantic',
'-Wundef',
'-Wsign-conversion',
'-Wuninitialized',
'-Wshadow',
'-Wunreachable-code',
'-Wswitch-default',
'-Wswitch',
'-Wcast-align',
'-Wmissing-include-dirs',
'-Winit-self',
'-Wdouble-promotion',
'-gdwarf-2',
'-fno-exceptions',
'-ffunction-sections',
'-fdata-sections',
'-fverbose-asm',
'-Wunused-parameter',
]
tests_c_args = []
if cc.get_argument_syntax() == 'msvc'
tests_c_args += [common_msvc_args, '/std:c11']
elif cc.get_argument_syntax() == 'gcc'
tests_c_args += [common_gcc_args, '-std=c11']
tests_c_args += '-Wstrict-prototypes'
if cc.get_id() == 'gcc'
tests_c_args += '-ffat-lto-objects'
endif
endif
tests_cpp_args = []
cxx = meson.get_compiler('cpp')
if cxx.get_argument_syntax() == 'msvc'
tests_cpp_args += [common_msvc_args, '/std:c++11']
elif cxx.get_argument_syntax() == 'gcc'
tests_cpp_args += [common_gcc_args, '-std=c++11']
if cxx.get_id() == 'gcc'
tests_cpp_args += '-ffat-lto-objects'
endif
endif

aliasing_opt = []
if cc.get_argument_syntax() == 'gcc'
aliasing_opt += '-fno-builtin-printf'
endif
aliasing_exe = executable(
'aliasing',
'aliasing.c',
cfg_header_file,
c_args: [aliasing_opt, tests_c_args],
dependencies: [eyalroz_printf_dep],
include_directories: '..',
)
test('printf.aliasing', aliasing_exe)


non_std_fmt_define = []
if get_option('test_with_non_standard_format_strings')
non_std_fmt_define += '-DTEST_WITH_NON_STANDARD_FORMAT_STRINGS'
endif

autotest_exe = executable(
'autotest',
'autotest.cpp',
cfg_header_file,
cpp_args: [non_std_fmt_define, tests_cpp_args],
implicit_include_directories: false,
include_directories: '..',
dependencies: eyalroz_printf_dep,
)
# Not running autotest by default - it's randomized after all.

if get_option('alias_standard_function_names') != 'soft'
test_suite_exe = executable(
'test_suite',
'test_suite.cpp',
cfg_header_file,
cpp_args: ['-DPRINTF_INCLUDE_CONFIG_H', non_std_fmt_define, tests_cpp_args],
include_directories: ['..', '../src'],
)
test('printf.test_suite', test_suite_exe)
endif