Skip to content

Commit 93b520f

Browse files
kassanexiaoxiang781216
authored andcommitted
swift6 embedded support
1 parent 7ff17d0 commit 93b520f

6 files changed

Lines changed: 124 additions & 0 deletions

File tree

‎arch/arm/src/common/Toolchain.defs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ include $(TOPDIR)/tools/Rust.defs
416416

417417
include $(TOPDIR)/tools/D.defs
418418

419+
# Swift 6 toolchain
420+
421+
include $(TOPDIR)/tools/Swift.defs
422+
419423
# Shared library build flags
420424

421425
SHCCFLAGS = -fPIC -fPIE -fvisibility=default

‎arch/risc-v/src/common/Toolchain.defs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ include $(TOPDIR)/tools/Rust.defs
421421

422422
include $(TOPDIR)/tools/D.defs
423423

424+
# Swift 6 toolchain
425+
426+
include $(TOPDIR)/tools/Swift.defs
427+
424428
# Shared library build flags
425429

426430
SHCCFLAGS = -fPIC -fPIE -fvisibility=default

‎boards/sim/sim/sim/scripts/Make.defs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ include $(TOPDIR)/tools/Rust.defs
196196

197197
include $(TOPDIR)/tools/D.defs
198198

199+
# Swift 6 toolchain
200+
201+
include $(TOPDIR)/tools/Swift.defs
202+
199203
CFLAGS := $(ARCHOPTIMIZATION) $(ARCHCFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
200204
CXXFLAGS := $(ARCHOPTIMIZATION) $(ARCHCXXFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
201205
CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)

‎tools/Config.mk‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,25 @@ define COMPILED
381381
$(ECHO_END)
382382
endef
383383

384+
# COMPILESWIFT - Default macro to compile one Swift file
385+
# Example: $(call COMPILESWIFT, in-file, out-file)
386+
#
387+
# Depends on these settings defined in board-specific Make.defs file
388+
# installed at $(TOPDIR)/Make.defs:
389+
#
390+
# SWIFTC - The command to invoke the Swift compiler
391+
# SWIFTFLAGS - Options to pass to the Swift compiler
392+
#
393+
# '<filename>.swift_SWIFTFLAGS += <options>' may also be used, as an example, to
394+
# change the options used with the single file <filename>.swift. The same
395+
# applies mutatis mutandis.
396+
397+
define COMPILESWIFT
398+
$(ECHO_BEGIN)"SWIFTC: $1 "
399+
$(Q) $(SWIFTC) -c $(SWIFTFLAGS) $($(strip $1)_SWIFTFLAGS) $1 -o $2
400+
$(ECHO_END)
401+
endef
402+
384403
# ASSEMBLE - Default macro to assemble one assembly language file
385404
# Example: $(call ASSEMBLE, in-file, out-file)
386405
#

‎tools/Swift.defs‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
############################################################################
2+
# tools/Swift.defs
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
############################################################################
20+
21+
# required: Swift 6
22+
23+
SWIFTC := swiftc
24+
25+
SWIFTFLAGS := -enable-experimental-feature Embedded -wmo
26+
27+
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
28+
SWIFTFLAGS += -g
29+
endif
30+
31+
ifeq ($(CONFIG_DEBUG_NOOPT),y)
32+
SWIFTFLAGS += -Osize
33+
endif
34+
35+
# Special handling for the SIM
36+
37+
ifeq ($(CONFIG_ARCH_SIM),y)
38+
ifeq ($(CONFIG_HOST_LINUX),y)
39+
ifeq ($(LLVM_ARCHTYPE),x86)
40+
# Only for x86 based host or x64 but m32 build
41+
SWIFTFLAGS += -target i686-unknown-linux-$(LLVM_ABITYPE)
42+
else
43+
# For other archs, such as aarch64, arm etc
44+
SWIFTFLAGS += -target $(LLVM_ARCHTYPE)-unknown-linux-$(LLVM_ABITYPE)
45+
SWIFTFLAGS += -target-cpu $(LLVM_CPUTYPE)
46+
endif
47+
else ifeq ($(CONFIG_HOST_MACOS),y)
48+
# Triple target [x86/arm64]-apple-macosx[min_version]
49+
ifeq ($(LLVM_ARCHTYPE),aarch64)
50+
SWIFTFLAGS += -target arm64-apple-macosx11.7.1
51+
else
52+
SWIFTFLAGS += -target $(LLVM_ARCHTYPE)-apple-macosx10.9.0
53+
endif
54+
endif
55+
else ifeq ($(CONFIG_ARCH_RISCV),y)
56+
# Target triple is riscv[32|64]-unknown-none-eabi
57+
SWIFTFLAGS += -target $(LLVM_ARCHTYPE)-none-none-eabi
58+
ifeq ($(CONFIG_ARCH_FPU),y)
59+
SWIFTFLAGS += -Xcc -march=rv32imafc_zicsr_zifencei
60+
else ifeq ($(CONFIG_ARCH_DPFPU),y)
61+
SWIFTFLAGS := -Xcc -march=rv32imafdc_zicsr_zifencei
62+
else
63+
SWIFTFLAGS += -Xcc -march=rv32imac_zicsr_zifencei
64+
endif
65+
66+
# Handle ABI and CPU
67+
ifeq ($(CONFIG_ARCH_RV32),y)
68+
SWIFTFLAGS += -target-cpu generic-rv32
69+
SWIFTFLAGS += -Xcc -mabi=ilp32d
70+
else ifeq ($(CONFIG_ARCH_RV64),y)
71+
SWIFTFLAGS += -target-cpu generic-rv64
72+
SWIFTFLAGS += -Xcc -mabi=lp64d
73+
endif
74+
else
75+
# For arm, but there are some other archs not support yet,
76+
# such as xtensa, x86 bare metal, etc.
77+
SWIFTFLAGS += -target $(LLVM_ARCHTYPE)-none-none-$(LLVM_ABITYPE)
78+
SWIFTFLAGS += -target-cpu $(LLVM_CPUTYPE)
79+
endif
80+
81+
82+
# Note for reference - all embedded targets available
83+
# see: ls ${SWIFT_PREFIX_PATH}/lib/swift/embedded/Swift.swiftmodule/
84+
#
85+
# aarch64-none-none-elf, arm64-apple-none-macho,
86+
# armv4t-none-none-eabi, armv6-apple-none-macho, armv6-none-none-eabi,
87+
# armv6m-apple-none-macho, armv6m-none-none-eabi, armv7-apple-none-macho,
88+
# armv7-none-none-eabi, armv7em-apple-none-macho, armv7em-none-none-eabi,
89+
# avr-none-none-elf, i686-unknown-none-elf, riscv32-none-none-eabi,
90+
# riscv64-none-none-eabi, wasm32-unknown-none-wasm, wasm64-unknown-none-wasm,
91+
# x86_64-unknown-linux-gnu, x86_64-unknown-none-elf,

‎tools/mkexport.sh‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ echo "ZIG = ${ZIG}" >>"${EXPORTDIR}/scripts/Make.defs"
252252
echo "ZIGFLAGS = ${ZIGFLAGS}" >>"${EXPORTDIR}/scripts/Make.defs"
253253
echo "DC = ${DC}" >>"${EXPORTDIR}/scripts/Make.defs"
254254
echo "DFLAGS = ${DFLAGS}" >>"${EXPORTDIR}/scripts/Make.defs"
255+
echo "SWIFTC = ${SWIFTC}" >>"${EXPORTDIR}/scripts/Make.defs"
256+
echo "SWIFTFLAGS = ${SWIFTFLAGS}" >>"${EXPORTDIR}/scripts/Make.defs"
255257
echo "NXFLATLDFLAGS1 = ${NXFLATLDFLAGS1}" >>"${EXPORTDIR}/scripts/Make.defs"
256258
echo "NXFLATLDFLAGS2 = ${NXFLATLDFLAGS2}" >>"${EXPORTDIR}/scripts/Make.defs"
257259
echo "OBJEXT = ${OBJEXT}" >>"${EXPORTDIR}/scripts/Make.defs"

0 commit comments

Comments
 (0)