AparokshaUI/adwaita-swift

Following Hello World tutorial on macos fails

jrwren opened this issue · 5 comments

Describe the bug

Following https://github.com/AparokshaUI/adwaita-swift/blob/main/user-manual/Basics/HelloWorld.md on macos 14.4 and get import error

To Reproduce

Do the tutorial on macos 14.4

See it fail on swift run step.

Expected behavior

What the tutorial says.

Additional context

$ swift run
Fetching https://github.com/AparokshaUI/Adwaita
Fetched https://github.com/AparokshaUI/Adwaita from cache (1.53s)
Computing version for https://github.com/AparokshaUI/Adwaita
Computed https://github.com/AparokshaUI/Adwaita at 0.2.4 (0.26s)
Fetching https://github.com/david-swift/LevenshteinTransformations
Fetched https://github.com/david-swift/LevenshteinTransformations from cache (0.36s)
Computing version for https://github.com/david-swift/LevenshteinTransformations
Computed https://github.com/david-swift/LevenshteinTransformations at 0.1.2 (0.27s)
Creating working copy for https://github.com/david-swift/LevenshteinTransformations
Working copy of https://github.com/david-swift/LevenshteinTransformations resolved at 0.1.2
Creating working copy for https://github.com/AparokshaUI/Adwaita
Working copy of https://github.com/AparokshaUI/Adwaita resolved at 0.2.4
warning: 'helloworld': dependency 'adwaita' is not used by any target
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
/Users/jrwren/src/HelloWorld/.build/arm64-apple-macosx/debug/Adwaita.build/module.modulemap:2:12: error: header '/Users/jrwren/src/HelloWorld/.build/arm64-apple-macosx/debug/Adwaita.build/Adwaita-Swift.h' not found
    header "/Users/jrwren/src/HelloWorld/.build/arm64-apple-macosx/debug/Adwaita.build/Adwaita-Swift.h"
           ^
/Users/jrwren/src/HelloWorld/Sources/main.swift:1:8: error: could not build Objective-C module 'Adwaita'
import Adwaita
       ^
/Users/jrwren/src/HelloWorld/.build/arm64-apple-macosx/debug/Adwaita.build/module.modulemap:2:12: error: header '/Users/jrwren/src/HelloWorld/.build/arm64-apple-macosx/debug/Adwaita.build/Adwaita-Swift.h' not found
    header "/Users/jrwren/src/HelloWorld/.build/arm64-apple-macosx/debug/Adwaita.build/Adwaita-Swift.h"
           ^
/Users/jrwren/src/HelloWorld/Sources/main.swift:1:8: error: could not build Objective-C module 'Adwaita'
import Adwaita
       ^
error: fatalError

Sorry, there is a step missing in that tutorial.

You have to add the dependency to the HelloWorld target as well:

targets: [
    // Targets are the basic building blocks of a package, defining a module or a test suite.
    // Targets can depend on other targets in this package and products from dependencies.
    .executableTarget(
        name: "HelloWorld",
        dependencies: [.product(name: "Adwaita", package: "Adwaita")]
    ),
]

Thank you for reporting this! Does it work after adding the dependency to the target?

It goes further and gives a different error:

error: the executable 'HelloWorld' requires macos 10.13, but depends on the product 'Adwaita' which requires macos 10.15; consider changing the executable 'HelloWorld' to require macos 10.15 or later, or the product 'Adwaita' to require macos 10.13 or earlier.
error: the executable 'HelloWorld' requires macos 10.13, but depends on the product 'Adwaita' which requires macos 10.15; consider changing the executable 'HelloWorld' to require macos 10.15 or later, or the product 'Adwaita' to require macos 10.13 or earlier.

Thanks for the help. I'll send a PR for the tutorial if that is acceptable.

I added

       platforms: [
        .macOS(.v10_15)
    ],

and it builds and runs. THANKS!

I've followed the tutorial on macOS myself now and got the error 'main' attribute cannot be used in a module that contains top-level code. As soon as I renamed the main.swift to HelloWorld.swift the error disappeared. I'll have to add this to the tutorial if there's no more elegant solution.

I'll add the macOS version specification to the tutorial as well.

I added the file name thing as well in 409dfb6. Thanks for reporting!