From 704bec9aea1aefcd902c49573ee57ab92bbdae1e Mon Sep 17 00:00:00 2001 From: Gurchetan Singh Date: Tue, 4 Jun 2024 15:48:08 -0700 Subject: [PATCH] rutabaga_gfx/ffi: add meson build This is somewhat more modern than the Makefile. Both just invoke cargo under the hood. The proper solution may come when Meson starts supporting external crates: https://github.com/mesonbuild/meson/issues/2173 Right now, this is a just a minimal version for developers. A known issue is modifying dependent crates (rutabaga_gfx) doesn't cause a rebuild. A solution is just `touch src/lib.rs` in ffi. Also, `ninja -C build/ clean` isn't recommended. Just do cargo clean. BUG=344998548 TEST=meson setup build ninja -C build/ install Change-Id: Id5a142cc5cb5a8001198afc4d1cdbe800ec2ec23 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5599139 Reviewed-by: Daniel Verkamp Commit-Queue: Gurchetan Singh --- rutabaga_gfx/ffi/Makefile | 76 ------------------------------ rutabaga_gfx/ffi/meson.build | 46 ++++++++++++++++++ rutabaga_gfx/ffi/meson_options.txt | 8 ++++ 3 files changed, 54 insertions(+), 76 deletions(-) delete mode 100644 rutabaga_gfx/ffi/Makefile create mode 100644 rutabaga_gfx/ffi/meson.build create mode 100644 rutabaga_gfx/ffi/meson_options.txt diff --git a/rutabaga_gfx/ffi/Makefile b/rutabaga_gfx/ffi/Makefile deleted file mode 100644 index f8c7820bfa..0000000000 --- a/rutabaga_gfx/ffi/Makefile +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright 2023 The ChromiumOS Authors -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -prefix ?= /usr/local -libdir = ${prefix}/lib -includedir = ${prefix}/include/rutabaga_gfx - -UNAME := $(shell uname -s) - -GFXSTREAM_DEP = gfxstream_backend - -ifdef debug - release := - target :=debug - extension :=debug - OUT = target/debug -else - release :=--release - target :=release - extension := - OUT = target/release -endif - -# Remember to change ffi/build.rs if this changes. -RUTABAGA_VERSION_MAJOR := 0 -SRC ?= src - -ifeq ($(UNAME), Linux) -LIB_NAME := librutabaga_gfx_ffi.so -endif - -ifeq ($(UNAME), Darwin) -LIB_NAME := librutabaga_gfx_ffi.dylib -endif - -gfxstream_feature := -ifeq ($(shell pkg-config --exists $(GFXSTREAM_DEP) && echo 1),1) - gfxstream_feature :=--features=gfxstream -endif - -RUTABAGA_VERSION := $(RUTABAGA_VERSION_MAJOR).1.3 - -all: build - -build: - cargo build $(gfxstream_feature) $(release) - -install: build -ifeq ($(UNAME), Linux) - install -D -m 755 $(OUT)/$(LIB_NAME) $(DESTDIR)$(libdir)/$(LIB_NAME).$(RUTABAGA_VERSION) -endif -ifeq ($(UNAME), Darwin) - install_name_tool -id $(DESTDIR)$(libdir)/$(LIB_NAME).$(RUTABAGA_VERSION) $(DESTDIR)$(libdir)/$(LIB_NAME) -endif - - ln -sf $(LIB_NAME).$(RUTABAGA_VERSION) $(DESTDIR)$(libdir)/$(LIB_NAME).$(RUTABAGA_VERSION_MAJOR) - ln -sf $(LIB_NAME).$(RUTABAGA_VERSION) $(DESTDIR)$(libdir)/$(LIB_NAME) - -ifeq ($(UNAME), Linux) - install -D -m 0644 $(OUT)/rutabaga_gfx_ffi.pc $(DESTDIR)$(libdir)/pkgconfig/rutabaga_gfx_ffi.pc - install -D -m 0644 $(SRC)/include/rutabaga_gfx_ffi.h $(DESTDIR)$(includedir)/rutabaga_gfx_ffi.h -endif -ifeq ($(UNAME), Darwin) - install -m 0644 $(OUT)/rutabaga_gfx_ffi.pc $(DESTDIR)$(libdir)/pkgconfig/rutabaga_gfx_ffi.pc - install -m 0644 $(SRC)/include/rutabaga_gfx_ffi.h $(DESTDIR)$(includedir)/rutabaga_gfx_ffi.h -endif - -clean: - cargo clean $(release) - -distclean: - cargo clean $(release) - -help: - @echo "usage: make $(prog) [debug=1]" diff --git a/rutabaga_gfx/ffi/meson.build b/rutabaga_gfx/ffi/meson.build new file mode 100644 index 0000000000..ebb0c07d37 --- /dev/null +++ b/rutabaga_gfx/ffi/meson.build @@ -0,0 +1,46 @@ +# Copyright 2024 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +project('rutabaga_gfx_ffi', ['rust', 'c'], + version: '0.1.3') + +target_os = host_machine.system() + +# By default cargo would generate rutabaga_gfx_ffi.dll (without the lib +# prefix) for a Windows cdylib +if target_os == 'windows' + shared_lib = 'rutabaga_gfx_ffi.dll' +endif +if target_os == 'darwin' + shared_lib = 'librutabaga_gfx_ffi.dylib' +endif +if target_os == 'linux' + shared_lib = 'librutabaga_gfx_ffi.so' +endif + +cargo = find_program('cargo') +cmd = [cargo, 'build'] +with_gfxstream = get_option('gfxstream') +if with_gfxstream + cmd += '--features=gfxstream' +endif + +rutabaga_gfx_ffi_ct = custom_target( + 'rutabaga_gfx_ffi_build', + output: shared_lib, + input: ['src/lib.rs', 'Cargo.toml', 'build.rs'], + command: cmd, +) + +rutabaga_gfx_ffi_h = files('src/include/rutabaga_gfx_ffi.h') + +rutabaga_gfx_ffi = library( + 'rutabaga_gfx_ffi', + sources: [rutabaga_gfx_ffi_h, rutabaga_gfx_ffi_ct], + version: '0.1.3', + install: true, +) + +install_headers(rutabaga_gfx_ffi_h, + subdir: 'rutabaga_gfx') diff --git a/rutabaga_gfx/ffi/meson_options.txt b/rutabaga_gfx/ffi/meson_options.txt new file mode 100644 index 0000000000..8366814c2b --- /dev/null +++ b/rutabaga_gfx/ffi/meson_options.txt @@ -0,0 +1,8 @@ +# 2024 Android Open Source Project +# SPDX-License-Identifier: MIT +option( + 'gfxstream', + type : 'boolean', + value : false, + description : 'Build gfxstream in rutabaga_gfx_ffi', +)