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 Aug 30, 2024
1 parent ce2ad51 commit 752964e
Show file tree
Hide file tree
Showing 5 changed files with 600 additions and 0 deletions.
1 change: 1 addition & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2591,6 +2591,7 @@ source "libs/libc/Kconfig"
source "libs/libm/Kconfig"
source "libs/libxx/Kconfig"
source "libs/libdsp/Kconfig"
source "libs/librust/Kconfig"
endmenu

menu "Open Asymmetric Multi Processing"
Expand Down
23 changes: 23 additions & 0 deletions libs/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)
nuttx_add_library(rust lib_rust.c)
endif()
15 changes: 15 additions & 0 deletions libs/librust/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# 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 Checking"
default y
depends on SYSTEM_TIME64
depends on FS_LARGEFILE
depends on !SMALL_MEMORY
---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.
65 changes: 65 additions & 0 deletions libs/librust/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
############################################################################
# libs/librust/Makefile
#
# 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.
#
############################################################################

include $(TOPDIR)/Make.defs

ifeq ($(CONFIG_LIBRUST),y)
CSRCS += lib_rust.c
endif

AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))

SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)

BIN ?= librust$(LIBEXT)

all: $(BIN)
.PHONY: depend clean distclean

$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)

$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)

$(BIN): $(OBJS)
$(call ARCHIVE, $@, $(OBJS))

makedepfile: $(CSRCS:.c=.ddc) $(ASRCS:.S=.dds)
$(call CATFILE, Make.dep, $^)
$(call DELFILE, $^)

.depend: Makefile $(SRCS) $(TOPDIR)$(DELIM).config
$(Q) $(MAKE) makedepfile
$(Q) touch $@

depend: .depend

clean:
$(call DELFILE, $(BIN))
$(call CLEAN)

distclean: clean
$(call DELFILE, Make.dep)
$(call DELFILE, .depend)

-include Make.dep
Loading

0 comments on commit 752964e

Please sign in to comment.