Skip to content

Commit fbc4e67

Browse files
authored
Merge pull request #74818 from carlos4242/add-target-avr
[AVR] Initial AVR support
2 parents e630f66 + ee57481 commit fbc4e67

File tree

7 files changed

+28
-15
lines changed

7 files changed

+28
-15
lines changed

docs/EmbeddedSwift/UserManual.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ A typical setup and build + run cycle for an embedded development board involves
2222
- (1) Getting an SDK with the C compilers, headers and libraries for the target
2323
- (2) Building the C source code, and Swift source code into object files.
2424
- (3) Linking all the libraries, C object files, and Swift object files.
25-
- (4) Post-processing the linked firmware into a flashable format (UF2, BIN, or bespoke formats)
26-
- (5) Uploading the flashable binary to the board over a USB cable using some vendor-provided JTAG/SWD tool or by copying it to a fake USB Mass Storage volume presented by the board.
25+
- (4) Post-processing the linked firmware into a flashable format (UF2, BIN, HEX, or bespoke formats)
26+
- (5) Uploading the flashable binary to the board over a USB cable using some vendor-provided JTAG/SWD tool, by copying it to a fake USB Mass Storage volume presented by the board or a custom platform bootloader.
2727
- (6) Restarting the board, observing physical effects of the firmware (LEDs light up) or UART output over USB, or presence on network, etc.
2828

2929
Most of these steps are out of scope for this document, instead refer to the vendor provided documentation. This document only focuses on (2) from the list above, and it's important that you first get familiar with the details of firmware development for your board without Swift in the mix. Even if you want to build a completely pure Swift firmware, you are still going to need the vendor provided tooling for linking, post-processing, uploading, etc.

lib/Basic/LangOptions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ static const SupportedConditionalValue SupportedConditionalCompilationArches[] =
101101
"s390x",
102102
"wasm32",
103103
"riscv64",
104+
"avr"
104105
};
105106

106107
static const SupportedConditionalValue SupportedConditionalCompilationEndianness[] = {
@@ -541,6 +542,9 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
541542
case llvm::Triple::ArchType::riscv64:
542543
addPlatformConditionValue(PlatformConditionKind::Arch, "riscv64");
543544
break;
545+
case llvm::Triple::ArchType::avr:
546+
addPlatformConditionValue(PlatformConditionKind::Arch, "avr");
547+
break;
544548
default:
545549
UnsupportedArch = true;
546550

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %swift -typecheck %s -verify -target avr-none-none -disable-objc-interop -parse-stdlib
2+
3+
#if arch(avr) && os(none) && _runtime(_Native) && _endian(little)
4+
class C {}
5+
var x = C()
6+
#endif
7+
var y = x
8+

test/Parse/ConditionalCompilation/basicParseErrors.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct S {
8787

8888
#endif
8989

90-
#if arch(leg) // expected-warning {{unknown architecture for build configuration 'arch'}} expected-note{{did you mean 'arm'?}} {{10-13=arm}}
90+
#if arch(arn) // expected-warning {{unknown architecture for build configuration 'arch'}} expected-note{{did you mean 'arm'?}} {{10-13=arm}}
9191
#endif
9292

9393
#if _endian(mid) // expected-warning {{unknown endianness for build configuration '_endian'}} expected-note{{did you mean 'big'?}} {{13-16=big}}
@@ -123,26 +123,26 @@ undefinedFunc() // expected-error {{cannot find 'undefinedFunc' in scope}}
123123
#endif
124124

125125
/// Invalid platform condition arguments don't invalidate the whole condition.
126-
#if !arch(tecture) && !os(ystem) && !_endian(ness)
126+
#if !arch(arn) && !os(ystem) && !_endian(ness)
127127
// expected-warning@-1 {{unknown architecture for build configuration 'arch'}}
128-
// expected-note@-2 {{did you mean 'arm'?}} {{11-18=arm}}
128+
// expected-note@-2 {{did you mean 'arm'?}} {{11-14=arm}}
129129
// expected-warning@-3 {{unknown operating system for build configuration 'os'}}
130-
// expected-note@-4 {{did you mean 'OSX'?}} {{27-32=OSX}}
131-
// expected-note@-5 {{did you mean 'PS4'?}} {{27-32=PS4}}
132-
// expected-note@-6 {{did you mean 'none'?}} {{27-32=none}}
130+
// expected-note@-4 {{did you mean 'OSX'?}} {{23-28=OSX}}
131+
// expected-note@-5 {{did you mean 'PS4'?}} {{23-28=PS4}}
132+
// expected-note@-6 {{did you mean 'none'?}} {{23-28=none}}
133133
// expected-warning@-7 {{unknown endianness for build configuration '_endian'}}
134-
// expected-note@-8 {{did you mean 'big'?}} {{46-50=big}}
134+
// expected-note@-8 {{did you mean 'big'?}} {{42-46=big}}
135135
func fn_k() {}
136136
#endif
137137
fn_k()
138138

139-
#if os(cillator) || arch(ive)
139+
#if os(cillator) || arch(i3rm)
140140
// expected-warning@-1 {{unknown operating system for build configuration 'os'}}
141141
// expected-note@-2 {{did you mean 'macOS'?}} {{8-16=macOS}}
142142
// expected-note@-3 {{did you mean 'iOS'?}} {{8-16=iOS}}
143143
// expected-warning@-4 {{unknown architecture for build configuration 'arch'}}
144-
// expected-note@-5 {{did you mean 'arm'?}} {{26-29=arm}}
145-
// expected-note@-6 {{did you mean 'i386'?}} {{26-29=i386}}
144+
// expected-note@-5 {{did you mean 'arm'?}} {{26-30=arm}}
145+
// expected-note@-6 {{did you mean 'i386'?}} {{26-30=i386}}
146146
// expected-note@-7 {{did you mean 'visionOS'?}} {{8-16=visionOS}}
147147
func undefinedFunc() // ignored.
148148
#endif

utils/build-presets.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ build-subdir=buildbot_incremental
611611
release
612612
assertions
613613

614-
llvm-targets-to-build=X86;ARM;AArch64;PowerPC;RISCV
614+
llvm-targets-to-build=X86;ARM;AArch64;PowerPC;RISCV;AVR
615615

616616
libcxx
617617
llbuild

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ def create_argument_parser():
13551355
help='enable building llvm using modules')
13561356

13571357
option('--llvm-targets-to-build', store,
1358-
default='X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV;WebAssembly',
1358+
default='X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV;WebAssembly;AVR',
13591359
help='LLVM target generators to build')
13601360

13611361
option('--llvm-ninja-targets', append,

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@
235235
'llvm_ninja_targets_for_cross_compile_hosts': [],
236236
'llvm_max_parallel_lto_link_jobs':
237237
defaults.LLVM_MAX_PARALLEL_LTO_LINK_JOBS,
238-
'llvm_targets_to_build': 'X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV;WebAssembly',
238+
'llvm_targets_to_build':
239+
'X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV;WebAssembly;AVR',
239240
'tsan_libdispatch_test': False,
240241
'long_test': False,
241242
'lto_type': None,

0 commit comments

Comments
 (0)