Skip to content

Commit

Permalink
meson: Fix static build
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke authored and Marge Bot committed Mar 11, 2024
1 parent ad65100 commit 73d7167
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
6 changes: 4 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ library_dependencies_sole = [
]

library_dependencies = library_dependencies_sole
private_dependencies = []

target = get_option('triplet')

Expand All @@ -187,12 +188,13 @@ if host_system == 'windows'

foreach i: native_libs.stdout().split()
if i != 'msvcrt'
library_dependencies += cc.find_library(i, required: get_option('default_library') != 'shared')
private_dependencies += cc.find_library(i, required: get_option('default_library') != 'shared')
endif
endforeach
endif

library_dependencies += [m_dep, foundation_dep]
private_dependencies += [m_dep, foundation_dep]
library_dependencies += private_dependencies

cargo_toml = meson.project_source_root() / 'Cargo.toml'

Expand Down
16 changes: 6 additions & 10 deletions meson/cargo_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,15 @@
g = parser.add_argument_group("Outputs")
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument(
"--extensions",
nargs="*",
default=[],
help="filename extensions for libraries (so, a, dll, lib, dylib)",
"--extension", help="filename extension for the static library (a, lib)",
)
group.add_argument("--bin", help="Name of binary to build")

args = parser.parse_args()

if args.command == 'test':
if args.extensions or args.bin:
raise ValueError('Cargo test does not take --extensions or --bin')
if args.extension or args.bin:
raise ValueError('Cargo test does not take --extension or --bin')

cargo_target_dir = Path(args.project_build_root) / "target"

Expand Down Expand Up @@ -145,10 +142,9 @@

if args.command in ["cbuild", "build"]:
# Copy so/dll/etc files to build dir
if args.extensions:
for ext in args.extensions:
for f in cargo_target_dir.glob(f"**/{buildtype}/*.{ext}"):
shutil.copy(f, args.current_build_dir)
if args.extension:
for f in cargo_target_dir.glob(f"**/{buildtype}/*.{args.extension}"):
shutil.copy(f, args.current_build_dir)
# Copy binary and, if applicable, the corresponding .pdb file, to build dir
else:
binary = Path(cargo_target_output_dir / buildtype / args.bin)
Expand Down
53 changes: 36 additions & 17 deletions rsvg/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ rust_artifacts = custom_target(
build_by_default: true,
output: '@0@rsvg_@1@.@2@'.format(lib_prefix, librsvg_api_major, ext_static),
console: true,
install: false,
depend_files: library_sources + librsvg_c_sources,
env: extra_env,
command: [
Expand All @@ -97,8 +96,10 @@ rust_artifacts = custom_target(
'--current-build-dir', '@OUTDIR@',
'--current-source-dir', meson.current_source_dir(),
'--packages', 'librsvg-c',
'--extensions', ext_static,
]
'--extension', ext_static,
],
install: get_option('default_library') == 'static',
install_dir: get_option('libdir'),
)

librsvg_c_lib = rust_artifacts[0]
Expand Down Expand Up @@ -200,18 +201,22 @@ else
)
endif

librsvg_lib = shared_library(
rsvg_ver,
rsvg_dummy,
link_whole: librsvg_c_lib,
link_args: link_args,
link_depends: librsvg_ver,
dependencies: library_dependencies,
include_directories: [includeinc],
vs_module_defs: librsvg_def,
install: true,
version: meson.project_version() # it's not exact as m4
)
if get_option('default_library') == 'shared'
librsvg_lib = shared_library(
rsvg_ver,
rsvg_dummy,
link_whole: librsvg_c_lib,
link_args: link_args,
link_depends: librsvg_ver,
dependencies: library_dependencies,
include_directories: [includeinc],
vs_module_defs: librsvg_def,
install: true,
version: meson.project_version() # it's not exact as m4
)
else
librsvg_lib = librsvg_c_lib
endif

# This is the main dependency to use for tests; it means "link to the library we just built"
librsvg_dep = declare_dependency(
Expand All @@ -229,6 +234,8 @@ librsvg_c_pc = pkg.generate(
description : 'library that renders svg files',
libraries : librsvg_lib,
subdirs: librsvg_pc,
requires: library_dependencies_sole,
libraries_private: private_dependencies,
)

if build_gir.allowed()
Expand Down Expand Up @@ -287,8 +294,20 @@ if build_gir.allowed()
]
endif

if get_option('default_library') == 'shared'
librsvg_gir = librsvg_lib
else
librsvg_gir = shared_library(
'rsvg-gir',
rsvg_dummy,
link_whole: librsvg_c_lib,
dependencies: library_dependencies,
include_directories: [includeinc],
)
endif

rsvg_gir = gnome.generate_gir(
librsvg_lib,
librsvg_gir,
namespace: 'Rsvg',
nsversion: '2.0',
symbol_prefix: [ 'rsvg', 'librsvg' ],
Expand Down Expand Up @@ -339,6 +358,6 @@ if build_tests.allowed()
'--current-source-dir', meson.current_source_dir(),
],
env: extra_env,
depends: librsvg_lib
depends: get_option('default_library') == 'shared' ? librsvg_lib : rust_artifacts
)
endif

0 comments on commit 73d7167

Please sign in to comment.