Skip to content

[embedded] Resolve a circular dependency problem in SwiftShims when using pico-libc #81857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ void importer::getNormalInvocationArguments(
"-isystem", searchPathOpts.RuntimeResourcePath,
});

if (LangOpts.hasFeature(Feature::Embedded)) {
invocationArgStrs.insert(invocationArgStrs.end(), {"-D__swift_embedded__"});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this apply to all clang importer calls now? If so we need to add it to the docs. (But I'm supportive)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, all ClangImporter calls.

}

// Enable Position Independence. `-fPIC` is not supported on Windows, which
// is implicitly position independent.
if (!triple.isOSWindows())
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SwiftShims/swift/shims/SwiftStdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

// Clang has been defining __INTxx_TYPE__ macros for a long time.
// __UINTxx_TYPE__ are defined only since Clang 3.5.
#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__)
#if !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__) && !defined(__swift_embedded__)
#include <stdint.h>
typedef int64_t __swift_int64_t;
typedef uint64_t __swift_uint64_t;
Expand Down
29 changes: 29 additions & 0 deletions test/embedded/builtin-float.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %empty-directory(%t)
// RUN: mkdir -p %t/include
// RUN: %{python} %utils/split_file.py -o %t %s

// RUN: %target-swift-frontend -target armv7em-none-none-eabi -emit-ir %t/Main.swift -enable-experimental-feature Embedded -module-cache-path %t/ModuleCache -Xcc -I%t/include

// REQUIRES: swift_in_compiler
// REQUIRES: optimized_stdlib
// REQUIRES: CODEGENERATOR=ARM
// REQUIRES: embedded_stdlib_cross_compiling
// REQUIRES: swift_feature_Embedded

// BEGIN Main.swift

print("hello")

// BEGIN include/stdint.h

#include <float.h>
typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
typedef __INT64_TYPE__ int64_t;
typedef __UINT64_TYPE__ uint64_t;
typedef __INT32_TYPE__ int32_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __INT16_TYPE__ int16_t;
typedef __UINT16_TYPE__ uint16_t;
typedef __INT8_TYPE__ int8_t;
typedef __UINT8_TYPE__ uint8_t;