diff --git a/docs/EmbeddedSwift/UserManual.md b/docs/EmbeddedSwift/UserManual.md index e7e12012cb52f..fc79ee430483c 100644 --- a/docs/EmbeddedSwift/UserManual.md +++ b/docs/EmbeddedSwift/UserManual.md @@ -22,8 +22,8 @@ A typical setup and build + run cycle for an embedded development board involves - (1) Getting an SDK with the C compilers, headers and libraries for the target - (2) Building the C source code, and Swift source code into object files. - (3) Linking all the libraries, C object files, and Swift object files. -- (4) Post-processing the linked firmware into a flashable format (UF2, BIN, or bespoke formats) -- (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. +- (4) Post-processing the linked firmware into a flashable format (UF2, BIN, HEX, or bespoke formats) +- (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. - (6) Restarting the board, observing physical effects of the firmware (LEDs light up) or UART output over USB, or presence on network, etc. 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. diff --git a/lib/Basic/LangOptions.cpp b/lib/Basic/LangOptions.cpp index 129847961dd41..dcdb23586c2a5 100644 --- a/lib/Basic/LangOptions.cpp +++ b/lib/Basic/LangOptions.cpp @@ -101,6 +101,7 @@ static const SupportedConditionalValue SupportedConditionalCompilationArches[] = "s390x", "wasm32", "riscv64", + "avr" }; static const SupportedConditionalValue SupportedConditionalCompilationEndianness[] = { @@ -541,6 +542,9 @@ std::pair LangOptions::setTarget(llvm::Triple triple) { case llvm::Triple::ArchType::riscv64: addPlatformConditionValue(PlatformConditionKind::Arch, "riscv64"); break; + case llvm::Triple::ArchType::avr: + addPlatformConditionValue(PlatformConditionKind::Arch, "avr"); + break; default: UnsupportedArch = true; diff --git a/test/Parse/ConditionalCompilation/avrTarget.swift b/test/Parse/ConditionalCompilation/avrTarget.swift new file mode 100644 index 0000000000000..2d9efa19380e3 --- /dev/null +++ b/test/Parse/ConditionalCompilation/avrTarget.swift @@ -0,0 +1,8 @@ +// RUN: %swift -typecheck %s -verify -target avr-none-none -disable-objc-interop -parse-stdlib + +#if arch(avr) && os(none) && _runtime(_Native) && _endian(little) +class C {} +var x = C() +#endif +var y = x + diff --git a/test/Parse/ConditionalCompilation/basicParseErrors.swift b/test/Parse/ConditionalCompilation/basicParseErrors.swift index e5fe7972f514c..9c0c6671efd55 100644 --- a/test/Parse/ConditionalCompilation/basicParseErrors.swift +++ b/test/Parse/ConditionalCompilation/basicParseErrors.swift @@ -87,7 +87,7 @@ struct S { #endif -#if arch(leg) // expected-warning {{unknown architecture for build configuration 'arch'}} expected-note{{did you mean 'arm'?}} {{10-13=arm}} +#if arch(arn) // expected-warning {{unknown architecture for build configuration 'arch'}} expected-note{{did you mean 'arm'?}} {{10-13=arm}} #endif #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}} #endif /// Invalid platform condition arguments don't invalidate the whole condition. -#if !arch(tecture) && !os(ystem) && !_endian(ness) +#if !arch(arn) && !os(ystem) && !_endian(ness) // expected-warning@-1 {{unknown architecture for build configuration 'arch'}} -// expected-note@-2 {{did you mean 'arm'?}} {{11-18=arm}} +// expected-note@-2 {{did you mean 'arm'?}} {{11-14=arm}} // expected-warning@-3 {{unknown operating system for build configuration 'os'}} -// expected-note@-4 {{did you mean 'OSX'?}} {{27-32=OSX}} -// expected-note@-5 {{did you mean 'PS4'?}} {{27-32=PS4}} -// expected-note@-6 {{did you mean 'none'?}} {{27-32=none}} +// expected-note@-4 {{did you mean 'OSX'?}} {{23-28=OSX}} +// expected-note@-5 {{did you mean 'PS4'?}} {{23-28=PS4}} +// expected-note@-6 {{did you mean 'none'?}} {{23-28=none}} // expected-warning@-7 {{unknown endianness for build configuration '_endian'}} -// expected-note@-8 {{did you mean 'big'?}} {{46-50=big}} +// expected-note@-8 {{did you mean 'big'?}} {{42-46=big}} func fn_k() {} #endif fn_k() -#if os(cillator) || arch(ive) +#if os(cillator) || arch(i3rm) // expected-warning@-1 {{unknown operating system for build configuration 'os'}} // expected-note@-2 {{did you mean 'macOS'?}} {{8-16=macOS}} // expected-note@-3 {{did you mean 'iOS'?}} {{8-16=iOS}} // expected-warning@-4 {{unknown architecture for build configuration 'arch'}} -// expected-note@-5 {{did you mean 'arm'?}} {{26-29=arm}} -// expected-note@-6 {{did you mean 'i386'?}} {{26-29=i386}} +// expected-note@-5 {{did you mean 'arm'?}} {{26-30=arm}} +// expected-note@-6 {{did you mean 'i386'?}} {{26-30=i386}} // expected-note@-7 {{did you mean 'visionOS'?}} {{8-16=visionOS}} func undefinedFunc() // ignored. #endif diff --git a/utils/build-presets.ini b/utils/build-presets.ini index bff56d1355612..ed5dbacf5717d 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -611,7 +611,7 @@ build-subdir=buildbot_incremental release assertions -llvm-targets-to-build=X86;ARM;AArch64;PowerPC;RISCV +llvm-targets-to-build=X86;ARM;AArch64;PowerPC;RISCV;AVR libcxx llbuild diff --git a/utils/build_swift/build_swift/driver_arguments.py b/utils/build_swift/build_swift/driver_arguments.py index 8b001ac905262..996a7c5d97ff9 100644 --- a/utils/build_swift/build_swift/driver_arguments.py +++ b/utils/build_swift/build_swift/driver_arguments.py @@ -1355,7 +1355,7 @@ def create_argument_parser(): help='enable building llvm using modules') option('--llvm-targets-to-build', store, - default='X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV;WebAssembly', + default='X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV;WebAssembly;AVR', help='LLVM target generators to build') option('--llvm-ninja-targets', append, diff --git a/utils/build_swift/tests/expected_options.py b/utils/build_swift/tests/expected_options.py index 52254bd0d584b..47e5faecaf891 100644 --- a/utils/build_swift/tests/expected_options.py +++ b/utils/build_swift/tests/expected_options.py @@ -235,7 +235,8 @@ 'llvm_ninja_targets_for_cross_compile_hosts': [], 'llvm_max_parallel_lto_link_jobs': defaults.LLVM_MAX_PARALLEL_LTO_LINK_JOBS, - 'llvm_targets_to_build': 'X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV;WebAssembly', + 'llvm_targets_to_build': + 'X86;ARM;AArch64;PowerPC;SystemZ;Mips;RISCV;WebAssembly;AVR', 'tsan_libdispatch_test': False, 'long_test': False, 'lto_type': None,