This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push: new 93b520f7b0 swift6 embedded support 93b520f7b0 is described below commit 93b520f7b05a843512529b617abb2a1f79a64ffd Author: Matheus Catarino <matheus-catar...@hotmail.com> AuthorDate: Thu Aug 22 11:34:23 2024 -0300 swift6 embedded support --- arch/arm/src/common/Toolchain.defs | 4 ++ arch/risc-v/src/common/Toolchain.defs | 4 ++ boards/sim/sim/sim/scripts/Make.defs | 4 ++ tools/Config.mk | 19 ++++++++ tools/Swift.defs | 91 +++++++++++++++++++++++++++++++++++ tools/mkexport.sh | 2 + 6 files changed, 124 insertions(+) diff --git a/arch/arm/src/common/Toolchain.defs b/arch/arm/src/common/Toolchain.defs index 019fd852a4..432ec8ab3b 100644 --- a/arch/arm/src/common/Toolchain.defs +++ b/arch/arm/src/common/Toolchain.defs @@ -416,6 +416,10 @@ include $(TOPDIR)/tools/Rust.defs include $(TOPDIR)/tools/D.defs +# Swift 6 toolchain + +include $(TOPDIR)/tools/Swift.defs + # Shared library build flags SHCCFLAGS = -fPIC -fPIE -fvisibility=default diff --git a/arch/risc-v/src/common/Toolchain.defs b/arch/risc-v/src/common/Toolchain.defs index 448a6baea3..2262632380 100644 --- a/arch/risc-v/src/common/Toolchain.defs +++ b/arch/risc-v/src/common/Toolchain.defs @@ -421,6 +421,10 @@ include $(TOPDIR)/tools/Rust.defs include $(TOPDIR)/tools/D.defs +# Swift 6 toolchain + +include $(TOPDIR)/tools/Swift.defs + # Shared library build flags SHCCFLAGS = -fPIC -fPIE -fvisibility=default diff --git a/boards/sim/sim/sim/scripts/Make.defs b/boards/sim/sim/sim/scripts/Make.defs index c67fb73021..8a32f4479c 100644 --- a/boards/sim/sim/sim/scripts/Make.defs +++ b/boards/sim/sim/sim/scripts/Make.defs @@ -196,6 +196,10 @@ include $(TOPDIR)/tools/Rust.defs include $(TOPDIR)/tools/D.defs +# Swift 6 toolchain + +include $(TOPDIR)/tools/Swift.defs + CFLAGS := $(ARCHOPTIMIZATION) $(ARCHCFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe CXXFLAGS := $(ARCHOPTIMIZATION) $(ARCHCXXFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) diff --git a/tools/Config.mk b/tools/Config.mk index 82cc57ced1..de959f0646 100644 --- a/tools/Config.mk +++ b/tools/Config.mk @@ -381,6 +381,25 @@ define COMPILED $(ECHO_END) endef +# COMPILESWIFT - Default macro to compile one Swift file +# Example: $(call COMPILESWIFT, in-file, out-file) +# +# Depends on these settings defined in board-specific Make.defs file +# installed at $(TOPDIR)/Make.defs: +# +# SWIFTC - The command to invoke the Swift compiler +# SWIFTFLAGS - Options to pass to the Swift compiler +# +# '<filename>.swift_SWIFTFLAGS += <options>' may also be used, as an example, to +# change the options used with the single file <filename>.swift. The same +# applies mutatis mutandis. + +define COMPILESWIFT + $(ECHO_BEGIN)"SWIFTC: $1 " + $(Q) $(SWIFTC) -c $(SWIFTFLAGS) $($(strip $1)_SWIFTFLAGS) $1 -o $2 + $(ECHO_END) +endef + # ASSEMBLE - Default macro to assemble one assembly language file # Example: $(call ASSEMBLE, in-file, out-file) # diff --git a/tools/Swift.defs b/tools/Swift.defs new file mode 100644 index 0000000000..fd51a3088c --- /dev/null +++ b/tools/Swift.defs @@ -0,0 +1,91 @@ +############################################################################ +# tools/Swift.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. +# +############################################################################ + +# required: Swift 6 + +SWIFTC := swiftc + +SWIFTFLAGS := -enable-experimental-feature Embedded -wmo + +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + SWIFTFLAGS += -g +endif + +ifeq ($(CONFIG_DEBUG_NOOPT),y) + SWIFTFLAGS += -Osize +endif + +# Special handling for the SIM + +ifeq ($(CONFIG_ARCH_SIM),y) + ifeq ($(CONFIG_HOST_LINUX),y) + ifeq ($(LLVM_ARCHTYPE),x86) + # Only for x86 based host or x64 but m32 build + SWIFTFLAGS += -target i686-unknown-linux-$(LLVM_ABITYPE) + else + # For other archs, such as aarch64, arm etc + SWIFTFLAGS += -target $(LLVM_ARCHTYPE)-unknown-linux-$(LLVM_ABITYPE) + SWIFTFLAGS += -target-cpu $(LLVM_CPUTYPE) + endif + else ifeq ($(CONFIG_HOST_MACOS),y) + # Triple target [x86/arm64]-apple-macosx[min_version] + ifeq ($(LLVM_ARCHTYPE),aarch64) + SWIFTFLAGS += -target arm64-apple-macosx11.7.1 + else + SWIFTFLAGS += -target $(LLVM_ARCHTYPE)-apple-macosx10.9.0 + endif + endif +else ifeq ($(CONFIG_ARCH_RISCV),y) + # Target triple is riscv[32|64]-unknown-none-eabi + SWIFTFLAGS += -target $(LLVM_ARCHTYPE)-none-none-eabi + ifeq ($(CONFIG_ARCH_FPU),y) + SWIFTFLAGS += -Xcc -march=rv32imafc_zicsr_zifencei + else ifeq ($(CONFIG_ARCH_DPFPU),y) + SWIFTFLAGS := -Xcc -march=rv32imafdc_zicsr_zifencei + else + SWIFTFLAGS += -Xcc -march=rv32imac_zicsr_zifencei + endif + + # Handle ABI and CPU + ifeq ($(CONFIG_ARCH_RV32),y) + SWIFTFLAGS += -target-cpu generic-rv32 + SWIFTFLAGS += -Xcc -mabi=ilp32d + else ifeq ($(CONFIG_ARCH_RV64),y) + SWIFTFLAGS += -target-cpu generic-rv64 + SWIFTFLAGS += -Xcc -mabi=lp64d + endif +else + # For arm, but there are some other archs not support yet, + # such as xtensa, x86 bare metal, etc. + SWIFTFLAGS += -target $(LLVM_ARCHTYPE)-none-none-$(LLVM_ABITYPE) + SWIFTFLAGS += -target-cpu $(LLVM_CPUTYPE) +endif + + +# Note for reference - all embedded targets available +# see: ls ${SWIFT_PREFIX_PATH}/lib/swift/embedded/Swift.swiftmodule/ +# +# aarch64-none-none-elf, arm64-apple-none-macho, +# armv4t-none-none-eabi, armv6-apple-none-macho, armv6-none-none-eabi, +# armv6m-apple-none-macho, armv6m-none-none-eabi, armv7-apple-none-macho, +# armv7-none-none-eabi, armv7em-apple-none-macho, armv7em-none-none-eabi, +# avr-none-none-elf, i686-unknown-none-elf, riscv32-none-none-eabi, +# riscv64-none-none-eabi, wasm32-unknown-none-wasm, wasm64-unknown-none-wasm, +# x86_64-unknown-linux-gnu, x86_64-unknown-none-elf, \ No newline at end of file diff --git a/tools/mkexport.sh b/tools/mkexport.sh index 60af60a3e2..a2bd2156c1 100755 --- a/tools/mkexport.sh +++ b/tools/mkexport.sh @@ -252,6 +252,8 @@ echo "ZIG = ${ZIG}" >>"${EXPORTDIR}/scripts/Make.defs" echo "ZIGFLAGS = ${ZIGFLAGS}" >>"${EXPORTDIR}/scripts/Make.defs" echo "DC = ${DC}" >>"${EXPORTDIR}/scripts/Make.defs" echo "DFLAGS = ${DFLAGS}" >>"${EXPORTDIR}/scripts/Make.defs" +echo "SWIFTC = ${SWIFTC}" >>"${EXPORTDIR}/scripts/Make.defs" +echo "SWIFTFLAGS = ${SWIFTFLAGS}" >>"${EXPORTDIR}/scripts/Make.defs" echo "NXFLATLDFLAGS1 = ${NXFLATLDFLAGS1}" >>"${EXPORTDIR}/scripts/Make.defs" echo "NXFLATLDFLAGS2 = ${NXFLATLDFLAGS2}" >>"${EXPORTDIR}/scripts/Make.defs" echo "OBJEXT = ${OBJEXT}" >>"${EXPORTDIR}/scripts/Make.defs"