Skip to content
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

Linux Support #6

Open
abegehr opened this issue Jan 11, 2024 · 8 comments · May be fixed by #7
Open

Linux Support #6

abegehr opened this issue Jan 11, 2024 · 8 comments · May be fixed by #7

Comments

@abegehr
Copy link

abegehr commented Jan 11, 2024

The package looks great and is easy to use!
However running on Linux as part of the vanilla Dockerfile for Vapor fails:

 > [app build  8/14] RUN swift build -c release                 --static-swift-stdlib                 -Xlinker -ljemalloc:
3.967 Building for production...
4.351 [0/874] Compiling _NumericsShims _NumericsShims.c
4.417 [1/874] Compiling _AtomicsShims.c
4.424 [2/874] Compiling errno.c
4.430 [2/874] Compiling a_type.c
4.430 [3/874] Compiling asn1_lib.c
4.430 [3/874] Compiling a_d2i_fp.c
4.431 [6/874] Compiling a_utctm.c
4.431 [6/874] Compiling a_time.c
6.993 [9/882] Compiling _NIOBase64 Base64.swift
7.041 [10/883] Compiling RealModule AlgebraicField.swift
7.335 [13/884] Compiling JSON Dictionary+JSON.swift
7.335 /build/.build/checkouts/json-apple/Sources/JSON/Dictionary+JSON.swift:73:9: error: cannot find 'CFBooleanGetTypeID' in scope
7.335         CFBooleanGetTypeID() == CFGetTypeID(self)
7.335         ^~~~~~~~~~~~~~~~~~
7.335 /build/.build/checkouts/json-apple/Sources/JSON/Dictionary+JSON.swift:73:33: error: cannot find 'CFGetTypeID' in scope
7.335         CFBooleanGetTypeID() == CFGetTypeID(self)
7.335                                 ^~~~~~~~~~~
7.335 /build/.build/checkouts/json-apple/Sources/JSON/JSON.swift:644:9: error: cannot find 'CFBooleanGetTypeID' in scope
7.335         CFBooleanGetTypeID() == CFGetTypeID(self)
7.335         ^~~~~~~~~~~~~~~~~~
7.335 /build/.build/checkouts/json-apple/Sources/JSON/JSON.swift:644:33: error: cannot find 'CFGetTypeID' in scope
7.335         CFBooleanGetTypeID() == CFGetTypeID(self)
7.335                                 ^~~~~~~~~~~
7.356 error: fatalError

The referenced symbol is in swift-corelibs-foundation: https://github.com/apple/swift-corelibs-foundation/blob/dbca8c7ddcfd19f7f6f6e1b60fd3ee3f748e263c/CoreFoundation/Base.subproj/CFRuntime.c#L732

@abegehr
Copy link
Author

abegehr commented Jan 11, 2024

Vapor docker file for reference: https://github.com/vapor/template/blob/main/Dockerfile

@kamleshboi69
Copy link

kamleshboi69 commented Jan 16, 2024

hi i checked this issue mayube the reason could be related to the inability to find 'CFBooleanGetTypeID' and 'CFGetTypeID' in scope. These are Core Foundation functions in Swift, and the error indicates that the compiler cannot find them during the build process.
check these
SDK Version and Target Platform:
Ensure that you are targeting an SDK version that includes the necessary Core Foundation frameworks. Sometimes, issues like this can arise if the SDK version is not compatible with the functions being used.

Importing CoreFoundation:
Make sure you have imported the CoreFoundation framework in your Swift files where these functions are used. You can add the following import statement at the top of the file:
try this
import CoreFoundation
Check Dependencies:
Verify that your project dependencies are correctly set up and that the versions of the libraries you are using are compatible with each other. It's possible that there is a version mismatch causing these symbols to be unavailable.

Compiler Flags:
Ensure that your Swift compiler flags are set up correctly. The build command in your log shows some additional flags like '--static-swift-stdlib' and '-Xlinker -ljemalloc'. Make sure these flags are appropriate for your project.

Swift Version:
Ensure that you are using a Swift version that is compatible with the libraries and dependencies you are using. Sometimes, certain functions may have been deprecated or changed in newer Swift versions.

Library Updates:
If you are using third-party libraries, check if there are any updates available. The issue might be resolved in a newer version of the library.

if yu have any problem ask

@abegehr
Copy link
Author

abegehr commented Feb 6, 2024

Thanks for your answer, @kamleshboi69! I've tried simply importing CoreFoundation but that doesn't solve it yet. I've found this thread on the Swift forums that I'm researching now: https://forums.swift.org/t/static-linking-on-linux-in-swift-5-3-1/41989

@abegehr
Copy link
Author

abegehr commented Feb 6, 2024

I've tried running without the compiler flags, however no luck. It fails with the same fatal error.

I'm on the latest swift-version 5.9, which is also indicated on json-apple's Package.swift: // swift-tools-version: 5.9

Here is a cut out of my Package.swift, showing the dependencies:

    dependencies: [
        // 💧 A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "4.92.1"),

        .package(url: "https://github.com/vapor/queues-redis-driver.git", from: "1.1.1"),
        .package(url: "https://github.com/orlandos-nl/IkigaJSON.git", from: "2.2.1"),
        .package(url: "https://github.com/shareup/json-apple.git", from: "1.4.0"),

    ],

=> all are updated to the latest version.

By the way, is this the proper way of adding json-apple to an executable target?

        .executableTarget(
            name: "App",
            dependencies: [
                .product(name: "Vapor", package: "vapor"),
                .product(name: "QueuesRedisDriver", package: "queues-redis-driver"),
                .product(name: "IkigaJSON", package: "IkigaJSON"),
                .product(name: "JSON", package: "json-apple"),
            ]
        ),

@abegehr
Copy link
Author

abegehr commented Feb 7, 2024

I'm finding the definition of CFBooleanGetTypeId and CFGetTypeId in swift-corelibs-foundation: https://github.com/apple/swift-corelibs-foundation/blob/main/Sources/Foundation/NSNumber.swift
However it fails when run on Linux.
@kamleshboi69, do you have a sample of json-apple successfully compiling for Linux?

@abegehr
Copy link
Author

abegehr commented Feb 7, 2024

Through this thread: https://forums.swift.org/t/foundation-on-linux-cfbooleangettypeid-cfgettypeid/2736/14
I found this issue: swiftlang/swift-corelibs-foundation#4573
Which states: "2. The existing ways on Darwin that you might perform this coercion do not work on Glibc/Linux because they rely on CoreFoundation types/functions which do not exist (e.g., kCFBooleanTrue, kCFBooleanFalse, CFBooleanGetTypeID, CFGetTypeID, etc...)"
EDIT: However, the issue has been fixed and as I linked to above the symbols exist in swift-corelibs-foundation.

@abegehr
Copy link
Author

abegehr commented Feb 7, 2024

I've setup a simple repro repo here: https://github.com/abegehr/json-apple-vapor

  1. vapor new json-apple-vapor -n
  2. add json-apple dependency in Package.swift. See: abegehr/json-apple-vapor@a7ed4bc#diff-f913940c58e8744a2af1c68b909bb6383e49007e6c5a12fb03104a9006ae677e
  3. Start docker and run docker build . in the repo root directory.

Fails with the same error:

1.922 [16/890] Compiling JSON Dictionary+JSON.swift
1.922 /build/.build/checkouts/json-apple/Sources/JSON/Dictionary+JSON.swift:73:9: error: cannot find 'CFBooleanGetTypeID' in scope
1.922         CFBooleanGetTypeID() == CFGetTypeID(self)
1.922         ^~~~~~~~~~~~~~~~~~
1.922 /build/.build/checkouts/json-apple/Sources/JSON/Dictionary+JSON.swift:73:33: error: cannot find 'CFGetTypeID' in scope
1.922         CFBooleanGetTypeID() == CFGetTypeID(self)
1.922                                 ^~~~~~~~~~~
1.922 /build/.build/checkouts/json-apple/Sources/JSON/JSON.swift:644:9: error: cannot find 'CFBooleanGetTypeID' in scope
1.922         CFBooleanGetTypeID() == CFGetTypeID(self)
1.922         ^~~~~~~~~~~~~~~~~~
1.922 /build/.build/checkouts/json-apple/Sources/JSON/JSON.swift:644:33: error: cannot find 'CFGetTypeID' in scope
1.922         CFBooleanGetTypeID() == CFGetTypeID(self)
1.922                                 ^~~~~~~~~~~
1.925 error: fatalError

@abegehr
Copy link
Author

abegehr commented Feb 7, 2024

I got the simple repro to work:
4. remove json-apple as dependency
5. copy over the two files JSON.swift and Dictionary.swift from json-apple's source
6. import CoreFoundation in both files (one is not enough).
=> it builds fine with docker build ./: abegehr/json-apple-vapor@7716bee
However, I'm not sure why, since Foundation.swiftinterface imports CoreFoundation.swiftinterface.

abegehr added a commit to abegehr/json-apple that referenced this issue Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants