From 85e67d697edba4849f20d481f5d670a83ab125a5 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 26 Apr 2024 12:30:57 +0200 Subject: [PATCH 1/7] Meson build: avoid using `add_languages('c')` to fix a build warning C is a required language it looks like, so just declare it normally in the `project()` call. The warning was: ``` meson.build:16: WARNING: add_languages is missing native:, assuming languages are wanted for both host and build. ``` Also clean up a stylistic issue and wrong comments for the threads dependency - it is no longer required. --- meson.build | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 9305092182..4bf1318ef3 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('highs', 'cpp', +project('highs', 'cpp', 'c', version : '1.6.0', meson_version: '>= 1.1.0', default_options : ['warning_level=1', @@ -13,7 +13,6 @@ _deps = [] # Dependencies _linkto = [] # All the sub-libraries _incdirs = [] # All the includes -add_languages('c', required: true) cc = meson.get_compiler('c') cppc = meson.get_compiler('cpp') @@ -72,9 +71,7 @@ if is_mingw endif # --------------------- Dependencies -# Required -threads_dep = dependency('threads', - required: false) +threads_dep = dependency('threads', required: false) _deps += threads_dep # Determine whether it is necessary to link libatomic. This could be the case From 769b8d5e3236041c68acdd3afc1fe3c49151e4a5 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 26 Apr 2024 13:07:00 +0200 Subject: [PATCH 2/7] Meson build: add note on issue on Windows with timestamp retrieval --- src/meson.build | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/meson.build b/src/meson.build index 785633e6f2..4ccfee2143 100644 --- a/src/meson.build +++ b/src/meson.build @@ -36,9 +36,12 @@ build_date = datetime.datetime.utcfromtimestamp( build_date_str = build_date.strftime('%Y-%m-%d') print(build_date_str) ''' + # Note: this is not guaranteed to work on Windows. This should be removed + # (as proposed in gh-1735), and otherwise moved into a .py script with + # a `#!/usr/bin/env python3` shebang, and `python3 -c` dropped. today_cmd = run_command('python3', '-c', python_getdate, - check: false) + check: false) today_str = today_cmd.stdout().strip() endif conf_data.set_quoted('HIGHS_COMPILATION_DATE', From 82909724d2377bc012f2e3c667fa3dd6787f8bbb Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 26 Apr 2024 14:52:35 +0200 Subject: [PATCH 3/7] Meson build: improve clarity of what libraries are being linked There was only one entry in `_linkto`, namely `highslib`. So the extra variable was not needed, removing it makes it clearer what is actually happening. --- check/meson.build | 4 ++-- meson.build | 1 - src/meson.build | 12 ++++-------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/check/meson.build b/check/meson.build index d54c09a037..1cf8e5663d 100644 --- a/check/meson.build +++ b/check/meson.build @@ -63,7 +63,7 @@ foreach test : test_array test.get(1), highs_conf_file], dependencies : _deps, - link_with : _linkto , + link_with : highslib, cpp_args : _args, include_directories: _incdirs, ), @@ -75,6 +75,6 @@ if get_option('with_c') test('test_capi', executable('capi_unit_tests', 'TestCAPI.c', include_directories: _incdirs, - link_with : _linkto , + link_with : highslib, )) endif diff --git a/meson.build b/meson.build index 4bf1318ef3..e23a932874 100644 --- a/meson.build +++ b/meson.build @@ -10,7 +10,6 @@ project('highs', 'cpp', 'c', # Add C++ compiler options _args = [] # Extra arguments _deps = [] # Dependencies -_linkto = [] # All the sub-libraries _incdirs = [] # All the includes cc = meson.get_compiler('c') diff --git a/src/meson.build b/src/meson.build index 4ccfee2143..72d368923f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -308,7 +308,6 @@ highslib = library('highs', dependencies: _deps, cpp_args: _args, c_args: _args, - link_with: _linkto, include_directories: _incdirs, pic: true, install: true) @@ -325,7 +324,7 @@ if get_option('with_fortran') _fsrcs, dependencies: _deps, cpp_args: _args, - link_with: [ _linkto, highslib ], + link_with: highslib, include_directories: _incdirs, pic: true, install: true) @@ -341,7 +340,7 @@ if get_option('with_csharp') _cs_srcs, dependencies: _deps, cpp_args: _args, - link_with: [ _linkto, highslib ], + link_with: highslib, include_directories: _incdirs, pic: true, install: true) @@ -361,16 +360,13 @@ if get_option('with_c') _c_src, dependencies: _deps, cpp_args: _args, - link_with: [ _linkto, highslib ], + link_with: highslib, include_directories: _incdirs, pic: true, install: true) endif - -_linkto += highslib - -highs_dep = declare_dependency(link_with: _linkto, +highs_dep = declare_dependency(link_with: highslib, dependencies: _deps, include_directories: _incdirs, ) From d4ee97ac180e959001d8ec19764be1beca90d0a8 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 26 Apr 2024 15:12:13 +0200 Subject: [PATCH 4/7] Meson build: ensure symbols from static library don't get reexported This is both safer and reduces the binary size of the Python extension modules that link against `libhighs.a`. --- src/meson.build | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/meson.build b/src/meson.build index 72d368923f..c9031d89c0 100644 --- a/src/meson.build +++ b/src/meson.build @@ -303,12 +303,20 @@ highslib_srcs = [ ] +symbol_visibility = 'default' +if get_option('default_library') == 'static' + # Ensure that if we link a static library into a shared library, + # private symbols don't get re-exported. + symbol_visibility = 'inlineshidden' +endif + highslib = library('highs', highslib_srcs, dependencies: _deps, cpp_args: _args, c_args: _args, include_directories: _incdirs, + gnu_symbol_visibility: symbol_visibility, pic: true, install: true) From b094f96049f84bf4b65406d3358690ab56472f0c Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 26 Apr 2024 15:21:48 +0200 Subject: [PATCH 5/7] Meson build: bump version to 1.7.0 --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index e23a932874..c20b4862ef 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('highs', 'cpp', 'c', - version : '1.6.0', + version : '1.7.0', meson_version: '>= 1.1.0', default_options : ['warning_level=1', 'cpp_std=c++17', From 3de2b8de39b84e2da42fab01c52c96a7626e00d4 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 26 Apr 2024 20:55:41 +0200 Subject: [PATCH 6/7] Meson build: ensure compiler flags to silence warnings are used portably The hardcoding may not work, and the flags were not used on any platform other than Linux. This caused a lot of warnings when building on macOS. --- meson.build | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index c20b4862ef..01193cc941 100644 --- a/meson.build +++ b/meson.build @@ -21,13 +21,16 @@ is_windows = host_system == 'windows' is_mingw = is_windows and cc.get_id() == 'gcc' # Conditional arguments -if host_system == 'linux' - _args += '-Wno-return-type' - _args += '-Wno-switch' - _args += '-Wno-unused-variable' - _args += '-Wno-unused-but-set-variable' - _args += '-Wno-unused-const-variable' -endif +_args += cppc.get_supported_arguments([ + '-Wno-return-type', + '-Wno-switch', + '-Wno-comment', + '-Wno-unused-variable', + '-Wno-unused-but-set-variable', + '-Wno-unused-const-variable', + '-Wno-unused-function', + '-Wno-unused-label', +]) if cppc.get_id() == 'msvc' add_project_arguments( @@ -58,10 +61,10 @@ endif cpu_family = host_machine.cpu_family() if cpu_family in ['x86_64', 'i686'] and not is_windows - add_project_arguments('-mpopcnt', language: 'cpp') + add_project_arguments(cppc.get_supported_arguments('-mpopcnt'), language: 'cpp') endif if cpu_family in ['ppc64', 'powerpc64'] and not meson.is_cross_build() - add_project_arguments('-mpopcntd', language: 'cpp') + add_project_arguments(cppc.get_supported_arguments('-mpopcntd'), language: 'cpp') endif if is_mingw From 1ab0520565a3e323f775532b9879d34c53222d3a Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 26 Apr 2024 21:23:06 +0200 Subject: [PATCH 7/7] Meson build: minor cleanup in highspy build config --- src/meson.build | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/meson.build b/src/meson.build index c9031d89c0..864c44e9ce 100644 --- a/src/meson.build +++ b/src/meson.build @@ -380,9 +380,11 @@ highs_dep = declare_dependency(link_with: highslib, ) if get_option('with_pybind11') - py_mod = import('python') - py = py_mod.find_installation(pure: false) + py = import('python').find_installation(pure: false) + pyb11_dep = [ + # py_dep is auto-added for Python >= 3.9, so it can be dropped here when + # that is the minimum supported Python version py.dependency(), dependency('pybind11') ]