Skip to content

Commit

Permalink
libs: Add static compatiblity check for Rust
Browse files Browse the repository at this point in the history
This patch adds a static compatiblity check
for most of structures from NuttX, which is used by Rust.

Currently, for most of them have a reserved field, which is for possible future use,
you can refer to https://github.com/no1wudi/libc/blob/39277b5357cb2aa7af1bd8344956ec292c35abed/src/unix/nuttx/mod.rs#L71
for more details.

I think we should define the initial version carefully, to avoid compatiblity problems in future as much as possible:
1. Struct reserved size is 2 pointer size, is it sufficient?
2. Which option should we preferred to use? Such as SYSTEM_TIME64 and FS_LARGEFILE?
3. Should we enable it by default to cover more cases in build CI? It can prevent introduce compatiblity issues.

Signed-off-by: Huang Qi <[email protected]>
  • Loading branch information
no1wudi committed Sep 24, 2024
1 parent 8288fe4 commit eabab17
Show file tree
Hide file tree
Showing 6 changed files with 1,015 additions and 0 deletions.
1 change: 1 addition & 0 deletions libs/libc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ source "libs/libc/regex/Kconfig"
source "libs/libc/gnssutils/Kconfig"
source "libs/libc/fdt/Kconfig"
source "libs/libc/queue/Kconfig"
source "libs/libc/librust/Kconfig"
1 change: 1 addition & 0 deletions libs/libc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ include wchar/Make.defs
include wctype/Make.defs
include wqueue/Make.defs
include fdt/Make.defs
include librust/Make.defs

# Use double delim to fix windows native build and give an error:
# makefile:132: *** target mode do not include“%”. stop.
Expand Down
23 changes: 23 additions & 0 deletions libs/libc/librust/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ##############################################################################
# libs/librust/CMakeLists.txt
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################

if(CONFIG_LIBRUST)
target_sources(c PRIVATE lib_rust.c)
endif()
16 changes: 16 additions & 0 deletions libs/libc/librust/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config LIBRUST
bool "Rust Runtime Compatibility Static Checker"
default y
depends on SYSTEM_TIME64
depends on FS_LARGEFILE
depends on !SMALL_MEMORY
depends on TLS_NELEM > 0
---help---
This option enables building and linking with Rust language support.
Currently, it only do static checking for the compatibility of structs
between Rust and C side.
30 changes: 30 additions & 0 deletions libs/libc/librust/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
############################################################################
# libs/libc/librust/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

ifeq ($(CONFIG_LIBRUST),y)
# Add the librust C files to the build

CSRCS += lib_rust.c

# Add the librust directory to the build

DEPPATH += --dep-path librust
VPATH += :librust
endif
Loading

0 comments on commit eabab17

Please sign in to comment.