Skip to content

Commit

Permalink
swift6 embedded support
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane authored and xiaoxiang781216 committed Aug 23, 2024
1 parent 7ff17d0 commit 93b520f
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 0 deletions.
4 changes: 4 additions & 0 deletions arch/arm/src/common/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions arch/risc-v/src/common/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions boards/sim/sim/sim/scripts/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions tools/Config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#
Expand Down
91 changes: 91 additions & 0 deletions tools/Swift.defs
Original file line number Diff line number Diff line change
@@ -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,
2 changes: 2 additions & 0 deletions tools/mkexport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 93b520f

Please sign in to comment.