Skip to content

Commit

Permalink
uapi meson recipe cleanup (#97)
Browse files Browse the repository at this point in the history
Install uapi crate and rustflags file in SDK:

- [x] meson uapi cleanup 

Postpone in next Pr to ease readability and thus reviewing process.

- [ ] Add rust-local-registry meson option
- [ ] install crate rule
- [ ] generate rustflags file
- [ ] install rustflags file
  • Loading branch information
fvalette-ledger authored Nov 27, 2024
2 parents 4a723a1 + 5e3d9a5 commit 7265dec
Show file tree
Hide file tree
Showing 18 changed files with 143 additions and 167 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.

project('sentry-kernel', 'c',
meson_version: '>=1.3.0',
meson_version: '>=1.4.0',
default_options: [
'c_std=gnu11', 'cpp_std=gnu++20',
'warning_level=3', 'optimization=s',
Expand Down
3 changes: 2 additions & 1 deletion support/arch/asm-cortex-m/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ target_cpu = 'cortex-@0@'.format(kconfig_data.get_unquoted('CONFIG_ARCH_ARM_CORT
target_has_fpu = kconfig_data.get('CONFIG_HAS_FPU', 0) == 1
target_use_fpu = kconfig_data.get('CONFIG_FPU_SOFT_ABI', 0) != 1

target_rust = kconfig_data.get_unquoted('CONFIG_RUSTC_TARGET')
target_rustargs = [
'--target=@0@'.format(kconfig_data.get_unquoted('CONFIG_RUSTC_TARGET')),
'--target=' + target_rust,
'-Ctarget-cpu='+ target_cpu,
]

Expand Down
1 change: 0 additions & 1 deletion uapi/.cargo-checksum.json

This file was deleted.

3 changes: 3 additions & 0 deletions uapi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2024 Ledger SAS
# SPDX-License-Identifier: Apache-2.0
**target*
3 changes: 0 additions & 3 deletions uapi/uapi/Cargo.toml → uapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ license = "Apache 2.0"
description = "Sentry kernel user API implementation"
categories = ["os::api"]

[lib]
path = "lib.rs"

[dependencies]

[dev-dependencies]
Expand Down
141 changes: 83 additions & 58 deletions uapi/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,113 @@ if not with_uapi_opt
subdir_done()
endif

if not meson.has_external_property('rust_target')
error('missing rust_target property in cross-file')
endif

add_languages('rust', native: false, required: true)

# Set rust toolchain config entry according to kconfig
# Note:
# configuration_file is done at top level meson.build in order to generate
# rust-toolchain.toml at build root directory.
rust_toolchain_in = files('rust-toolchain.toml.in')
rust_toolchain_config = configuration_data()
rust_toolchain_config.set('channel', get_option('rust-channel'))
rust_toolchain_config.set('target', kconfig_data.get_unquoted('CONFIG_RUSTC_TARGET'))

uapi_rust_std = 'rust_std=2021'
uapi_rust_libfile = files('uapi/lib.rs')

global_rust_build_args = [
'@' + fs.parent(kconfig_rustargs) / fs.name(kconfig_rustargs),
target_rustargs,
'-C', 'lto=true', '-C', 'relocation-model=pic', '-C', 'link-args=--emit-relocs'
]

rust_edition = '2021'
uapi_rust_std = 'rust_std=' + rust_edition
uapi_manifest = files('Cargo.toml')

subdir('include/uapi')
subdir('uapi')

py3 = pymod.find_installation('python3', modules: ['git'])

# XXX:
# This deps is designed for userspace (libshied) only
# As in linux kernel, uapi headers are not used w/ a kernel name and/or uapi
# prefix. So, add the uapi include subdir in "include_directories".
sentry_c_uapi_dep = declare_dependency(
link_with: uapi_rs_lib,
sources: [ uapi_h ],
compile_args: [ global_build_args, target_arch_args ],
include_directories: [ userspace_uapi_include_dir ],
subdir('src')

cargo = find_program('cargo', required: true)
cargo_fmt = find_program('cargo-fmt', required: false)
cargo_clippy = find_program('cargo-clippy', required: false)
cargo_index = find_program('cargo-index', required: false)

if with_doc_opt
uapi_doc = custom_target(
'doc-uapi',
input: uapi_manifest,
output: 'doc',
command: [cargo, 'doc', '--manifest-path', '@INPUT@'],
depend_files: [uapi_modules, uapi_libfile],
env: {'CARGO_TARGET_DIR':meson.current_build_dir()},
install: true,
install_dir: get_option('datadir') / 'doc/sentry-uapi',
install_tag: 'doc',
)

pkg_config = import('pkgconfig')
pkg_config.generate(
uapi_rs_lib,
filebase: 'uapi',
extra_cflags: [ global_build_args, target_arch_args ],
)
uapi_doc_alias = alias_target('doc-uapi', uapi_doc)
endif # with_doc

install_data(
'task.Kconfig',
install_dir : get_option('datadir') / 'configs',
)
# Following target are format/lint check and test
# These are declared as test entry in the `uapi` test suite

install_subdir(
'uapi',
install_dir: get_option('datadir') / 'cargo/repository/sentry-uapi',
strip_directory: true,
install_tag: 'devel',
)
if with_tests
cargo_manifest_opt = '--manifest-path=' + uapi_manifest[0].full_path()
cargo_targetdir_opt = '--target-dir=' + meson.current_build_dir()
cargo_target_opt = '--target=' + target_rust

vendoring_py_wrapper = '''
import git
repo = git.Repo(search_parent_directories=True)
print('{');
print(' "git": {')
print(' "sha1": "{}"'.format(repo.head.commit.tree.hexsha))
print('}');
'''

gen_cargo_hash = custom_target(
'forge_cargo_hashfile',
output: '.cargo_vcs_info.json',
command: [ py3, '-c', vendoring_py_wrapper ],
capture: true,
install: true,
install_dir: get_option('datadir') / 'cargo/repository/sentry-uapi',
install_tag: 'devel',
build_by_default: true,
if cargo_fmt.found()
test(
'cargo-fmt',
cargo_fmt,
args: [cargo_manifest_opt, '--check' ],
should_fail: true,
suite: 'uapi',
)
endif # cargo_fmt found

if cargo_clippy.found()
test(
'cargo-clippy',
cargo,
args: [
'clippy',
cargo_manifest_opt,
cargo_targetdir_opt,
cargo_target_opt,
'--no-deps',
'--',
'-Dwarnings',
],
should_fail: true,
suite: 'uapi',
)
endif # cargo clippy found

test(
'cargo-test',
cargo,
args: [
'test',
cargo_manifest_opt,
cargo_targetdir_opt,
'--',
'--test-threads=1',
],
is_parallel: false,
should_fail: true,
suite: 'uapi',
)

endif #with_tests


install_data(
'task.Kconfig',
install_dir : get_option('datadir') / 'configs',
)

install_data(
'.cargo-checksum.json',
install_dir: get_option('datadir') / 'cargo/repository/sentry-uapi',
summary(
{
'rust edition': rust_edition,
},
section: 'Target specific compile args'
)
File renamed without changes.
8 changes: 8 additions & 0 deletions uapi/src/arch/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: 2024 Ledger SAS
# SPDX-License-Identifier: Apache-2.0

uapi_modules += files('mod.rs')

if kconfig_data.get('CONFIG_ARCH_ARM_CORTEX_M', 0) == 1
uapi_modules += files('arm_cortex_m.rs')
endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
46 changes: 46 additions & 0 deletions uapi/src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# SPDX-FileCopyrightText: 2023-2024 Ledger SAS
# SPDX-License-Identifier: Apache-2.0

uapi_libfile = files('lib.rs')

# XXX:
# only lib.rs is required for static_library target but in order to export correct
# dependencies through meson introspect, we should add deps to inner modules
uapi_modules = files([
'panic.rs',
'svc_exchange.rs',
'syscall.rs',
'systypes.rs',
'uapi.rs',
])

subdir('arch')

uapi_lib = static_library(
'uapi',
sources : uapi_libfile,
rust_abi: 'c',
rust_args: global_rust_build_args,
override_options: [uapi_rust_std],
extra_files: uapi_modules,
install: true,
)

# XXX:
# This deps is designed for userspace (libshied) only
# As in linux kernel, uapi headers are not used w/ a kernel name and/or uapi
# prefix. So, add the uapi include subdir in "include_directories".
sentry_c_uapi_dep = declare_dependency(
link_with: uapi_lib,
sources: [ uapi_h ],
compile_args: [ global_build_args, target_arch_args ],
include_directories: [ userspace_uapi_include_dir ],
)

# Generate pkg config file uapi.pc for C app using c_ffi static library
pkg_config = import('pkgconfig')
pkg_config.generate(
uapi_lib,
filebase: 'uapi',
extra_cflags: [ global_build_args, target_arch_args ],
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion uapi/uapi/uapi.rs → uapi/src/uapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use crate::svc_exchange::*;
use crate::syscall;
use core::fmt;
use crate::systypes::*;

/// Emit an already formatted string through the Sentry kernel std log output
Expand Down
102 changes: 0 additions & 102 deletions uapi/uapi/meson.build

This file was deleted.

0 comments on commit 7265dec

Please sign in to comment.