Skip to content
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

default_both_libraries=static has no effect #14158

Open
ueno opened this issue Jan 20, 2025 · 3 comments
Open

default_both_libraries=static has no effect #14158

ueno opened this issue Jan 20, 2025 · 3 comments

Comments

@ueno
Copy link
Contributor

ueno commented Jan 20, 2025

Describe the bug
Suppose there is a meson.build file with:

project('foo', 'c')

foo_lib = both_libraries( 
  'foo',
  'foo.c',
  install: true,
)

and a foo.c file with:

int foo (void) {
  return 1;
}

With meson 1.6.1, running meson setup build -Ddefault_both_libraries=static still builds and installs both shared (.so) and static (.a) libraries of libfoo.

If I change both_libraries to library, and supply -Ddefault_library=static, it only builds a static library.

To Reproduce

See the above.

Expected behavior

When -Ddefault_both_libraries=static or -Ddefault_both_libraries=auto -Ddefault_library=static is specified, only a static library is built and installed.

system parameters

  • Is this a cross build or just a plain native build (for the same computer)?: Native build
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.): Fedora rawhide
  • what Python version are you using e.g. 3.8.0: Python 3.13.1
  • what meson --version: 1.6.1
  • what ninja --version if it's a Ninja build: 1.12.1
@eli-schwartz
Copy link
Member

Expected behavior

When -Ddefault_both_libraries=static or -Ddefault_both_libraries=auto -Ddefault_library=static is specified, only a static library is built and installed.

both_libraries() uses a shared code path with library(), and behaves identically to "the latter, if default_library=both".

It is intended for cases where the project author is convinced that offering the choice between default_library=static and default_library=both is bad, "because I absolutely positively require users to have both static and shared libraries".

The default_both_libraries option does something else entirely. And apparently the docs for it are very confusing, sorry! There would be no point in having the option choose which library is built and installed, since then it would just be library(). Instead, what this option does, as added by @bruchar1 in #12632, is allow meson.build targets such as executable() which link to the return value of both_libraries()`, to select whether they link a static or a shared executable. Previously, when you did this:

mylib = both_libraries('foolib', 'foolib.c', install: true)

myprog = executable('barprog', 'barprog.c', link_with: mylib, install: true)

barprog would always link dynamically to foolib, although other people using foolib could freely choose to link statically or dynamically by using -lfoolib together with -static or possibly even -static -lfoolib -Wl,-Bdynamic.

With this option you could do meson setup -Ddefault_both_libraries=static and you'd build and install shared as well as static libraries, but link barprog statically.

@bruchar1
Copy link
Member

What could I do to improve documentation?

@ueno
Copy link
Contributor Author

ueno commented Jan 21, 2025

@eli-schwartz thank you for the clarification.

@bruchar1 I would propose something along these lines:

diff --git a/docs/markdown/Builtin-options.md b/docs/markdown/Builtin-options.md
index 3a912805a..86b729ed0 100644
--- a/docs/markdown/Builtin-options.md
+++ b/docs/markdown/Builtin-options.md
@@ -183,11 +183,16 @@ fails.
 
 #### Details for `default_both_libraries`
 
-Since `1.6.0`, you can select the default type of library selected when using
-a `both_libraries` object. This can be either 'shared' (default value, compatible
-with previous meson versions), 'static', or 'auto'. With auto, the value from
-`default_library` option is used, unless it is 'both', in which case 'shared'
-is used instead.
+Since `1.6.0`, you can select the default type of library selected when using a
+`both_libraries` object. Note that, unlike `default_library`, this option does
+not affect how the library artifacts are built, but how they are internally
+linked to the applications (either executables or other libraries) within the
+same project.
+
+The possible values of this option are 'shared' (default value,
+compatible with previous meson versions), 'static', and 'auto'. With auto, the
+value from `default_library` option is used, unless it is 'both', in which case
+'shared' is used instead.
 
 When `default_both_libraries` is 'auto', passing a [[@both_libs]] dependency
 in [[both_libraries]] will link the static dependency with the static lib,

Does it make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants