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

Failed to reproduce "Generating a client in an Xcode project" example #57

Closed
AliakseiM opened this issue Jun 9, 2023 · 10 comments · Fixed by #58
Closed

Failed to reproduce "Generating a client in an Xcode project" example #57

AliakseiM opened this issue Jun 9, 2023 · 10 comments · Fixed by #58
Labels
area/documentation Improvements or additions to documentation. kind/bug Feature doesn't work as expected. size/S Small task. (A couple of hours of work.)

Comments

@AliakseiM
Copy link

Commit hash: 37255b7

Context: I just wanted to try example, but build fails.

Steps to reproduce:

  1. Create new Xcode project (iOS app, Swift, SwiftUI)
  2. Follow steps from tutorial including Section 1 and Section 2
  3. Build fails on Step 3 of Section 3

XCode Version 14.3 (14E222b)

$ swift --version
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
$uname -a
Darwin MacBook-Pro-Aleksej.local 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:24 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6000 arm64
@czechboy0
Copy link
Contributor

Hi @AliakseiM, can you also share the message of the build failure, please?

@AliakseiM
Copy link
Author

Hi @czechboy0, sure.

    cd /Users/alexey/Developer/ios/examples/swift-openapi/swift-openapi-ios
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -Xlinker -reproducible -target arm64-apple-ios16.4-simulator -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.4.sdk -L/Users/alexey/Library/Developer/Xcode/DerivedData/swift-openapi-ios-feadsqjpxalfivbzkcxwrdkhfssd/Build/Intermediates.noindex/EagerLinkingTBDs/Debug-iphonesimulator -L/Users/alexey/Library/Developer/Xcode/DerivedData/swift-openapi-ios-feadsqjpxalfivbzkcxwrdkhfssd/Build/Products/Debug-iphonesimulator -F/Users/alexey/Library/Developer/Xcode/DerivedData/swift-openapi-ios-feadsqjpxalfivbzkcxwrdkhfssd/Build/Intermediates.noindex/EagerLinkingTBDs/Debug-iphonesimulator -F/Users/alexey/Library/Developer/Xcode/DerivedData/swift-openapi-ios-feadsqjpxalfivbzkcxwrdkhfssd/Build/Products/Debug-iphonesimulator -filelist /Users/alexey/Library/Developer/Xcode/DerivedData/swift-openapi-ios-feadsqjpxalfivbzkcxwrdkhfssd/Build/Intermediates.noindex/swift-openapi-ios.build/Debug-iphonesimulator/GeneratedClient.build/Objects-normal/arm64/GeneratedClient.LinkFileList -install_name @rpath/GeneratedClient.framework/GeneratedClient -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/alexey/Library/Developer/Xcode/DerivedData/swift-openapi-ios-feadsqjpxalfivbzkcxwrdkhfssd/Build/Intermediates.noindex/swift-openapi-ios.build/Debug-iphonesimulator/GeneratedClient.build/Objects-normal/arm64/GeneratedClient_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/alexey/Library/Developer/Xcode/DerivedData/swift-openapi-ios-feadsqjpxalfivbzkcxwrdkhfssd/Build/Intermediates.noindex/swift-openapi-ios.build/Debug-iphonesimulator/GeneratedClient.build/Objects-normal/arm64/GeneratedClient.swiftmodule -Xlinker -no_adhoc_codesign -compatibility_version 1 -current_version 1 -Xlinker -dependency_info -Xlinker /Users/alexey/Library/Developer/Xcode/DerivedData/swift-openapi-ios-feadsqjpxalfivbzkcxwrdkhfssd/Build/Intermediates.noindex/swift-openapi-ios.build/Debug-iphonesimulator/GeneratedClient.build/Objects-normal/arm64/GeneratedClient_dependency_info.dat -o /Users/alexey/Library/Developer/Xcode/DerivedData/swift-openapi-ios-feadsqjpxalfivbzkcxwrdkhfssd/Build/Products/Debug-iphonesimulator/GeneratedClient.framework/GeneratedClient

Undefined symbols for architecture arm64:
  "_$s10Foundation3URLV14OpenAPIRuntimeE010validatingc9APIServerB0ACSS_tKcfC", referenced from:
      _$s15GeneratedClient7ServersO7server110Foundation3URLVyKFZ in Types.o
      _$s15GeneratedClient7ServersO7server210Foundation3URLVyKFZ in Types.o
  "_$s14OpenAPIRuntime10HTTPMethodV3getACvgZ", referenced from:
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKF14OpenAPIRuntime7RequestVAKKXEfU_ in Client.o
  "_$s14OpenAPIRuntime11HeaderFieldVN", referenced from:
      _$s14OpenAPIRuntime7RequestV4path5query6method12headerFields4bodyACSS_SSSgAA10HTTPMethodVSayAA11HeaderFieldVG10Foundation4DataVSgtcfcfA2_ in Client.o
  "_$s14OpenAPIRuntime15UniversalClientV4send5input12forOperation10serializer12deserializerq_x_SSAA7RequestVxKXEq_AA8ResponseVKXEtYaKr0_lF", referenced from:
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKFTY0_ in Client.o
  "_$s14OpenAPIRuntime15UniversalClientV4send5input12forOperation10serializer12deserializerq_x_SSAA7RequestVxKXEq_AA8ResponseVKXEtYaKr0_lFTu", referenced from:
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKFTY0_ in Client.o
  "_$s14OpenAPIRuntime15UniversalClientV9serverURL13configuration9transport11middlewaresAC10Foundation0F0V_AA13ConfigurationVAA0D9Transport_pSayAA0D10Middleware_pGtcfC", referenced from:
      _$s15GeneratedClient0B0V9serverURL13configuration9transport11middlewaresAC10Foundation0D0V_14OpenAPIRuntime13ConfigurationVAK0B9Transport_pSayAK0B10Middleware_pGtcfC in Client.o
  "_$s14OpenAPIRuntime15UniversalClientVMa", referenced from:
      _$s15GeneratedClient0B0V9serverURL13configuration9transport11middlewaresAC10Foundation0D0V_14OpenAPIRuntime13ConfigurationVAK0B9Transport_pSayAK0B10Middleware_pGtcfC in Client.o
      _$s14OpenAPIRuntime15UniversalClientVWOb in Client.o
      _$s15GeneratedClient0B0VWOc in Client.o
      _$s15GeneratedClient0B0VWOh in Client.o
      _$s15GeneratedClient0B0V9converter33_627C69B1B4EBE1C19DF11ABF1978AC15LL14OpenAPIRuntime9ConverterVvg in Client.o
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKF in Client.o
      _$s14OpenAPIRuntime15UniversalClientVWOc in Client.o
      ...
  "_$s14OpenAPIRuntime15UniversalClientVMn", referenced from:
      _symbolic _____ 14OpenAPIRuntime15UniversalClientV in Client.o
  "_$s14OpenAPIRuntime18_StringConvertibleMp", referenced from:
      _symbolic ______p 14OpenAPIRuntime18_StringConvertibleP in Client.o
  "_$s14OpenAPIRuntime19UndocumentedPayloadV23__derived_struct_equalsySbAC_ACtFZ", referenced from:
      _$s15GeneratedClient10OperationsO11getGreetingO6OutputO21__derived_enum_equalsySbAG_AGtFZ in Types.o
  "_$s14OpenAPIRuntime19UndocumentedPayloadVACycfC", referenced from:
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKFAI14OpenAPIRuntime8ResponseVKXEfU0_ in Client.o
  "_$s14OpenAPIRuntime19UndocumentedPayloadVMn", referenced from:
      _symbolic Si10statusCode______t 14OpenAPIRuntime19UndocumentedPayloadV in Types.o
  "_$s14OpenAPIRuntime19UndocumentedPayloadVN", referenced from:
      _$s15GeneratedClient10OperationsO11getGreetingO6OutputO4hash4intoys6HasherVz_tF in Types.o
      _$s14OpenAPIRuntime19UndocumentedPayloadVACSHAAWl in Types.o
  "_$s14OpenAPIRuntime19UndocumentedPayloadVSHAAMc", referenced from:
      _$s14OpenAPIRuntime19UndocumentedPayloadVACSHAAWl in Types.o
  "_$s14OpenAPIRuntime25suppressMutabilityWarningyyxzlF", referenced from:
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKF14OpenAPIRuntime7RequestVAKKXEfU_ in Client.o
  "_$s14OpenAPIRuntime7RequestV4path5query6method12headerFields4bodyACSS_SSSgAA10HTTPMethodVSayAA11HeaderFieldVG10Foundation4DataVSgtcfC", referenced from:
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKF14OpenAPIRuntime7RequestVAKKXEfU_ in Client.o
  "_$s14OpenAPIRuntime7RequestVN", referenced from:
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKF14OpenAPIRuntime7RequestVAKKXEfU_ in Client.o
  "_$s14OpenAPIRuntime9ConverterV18setQueryItemAsText2in4name5valueyAA7RequestVz_SSxSgtKAA18_StringConvertibleRzlF", referenced from:
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKF14OpenAPIRuntime7RequestVAKKXEfU_ in Client.o
  "_$s14OpenAPIRuntime9ConverterV19renderedRequestPath8template10parametersS2S_SayAA18_StringConvertible_pGtKF", referenced from:
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKF14OpenAPIRuntime7RequestVAKKXEfU_ in Client.o
  "_$s14OpenAPIRuntime9ConverterV20setHeaderFieldAsText2in4name5valueySayAA0eF0VGz_SSxSgtKAA18_StringConvertibleRzlF", referenced from:
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKF14OpenAPIRuntime7RequestVAKKXEfU_ in Client.o
  "_$s14OpenAPIRuntime9ConverterV21getResponseBodyAsJSON_4from12transformingq_xm_10Foundation4DataVq_xXEtKSeRzr0_lF", referenced from:
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKFAI14OpenAPIRuntime8ResponseVKXEfU0_ in Client.o
  "_$s14OpenAPIRuntime9ConverterV28validateContentTypeIfPresent2in9substringySayAA11HeaderFieldVG_SStKF", referenced from:
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKFAI14OpenAPIRuntime8ResponseVKXEfU0_ in Client.o
  "_$sSS14OpenAPIRuntime18_StringConvertibleAAWP", referenced from:
      _$s15GeneratedClient0B0V11getGreetingyAA10OperationsOADO6OutputOAG5InputVYaKF14OpenAPIRuntime7RequestVAKKXEfU_ in Client.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@AliakseiM
Copy link
Author

Btw, this worked fine for me:

$ swift run swift-openapi-generator generate --mode client --mode types --output-directory . openapi.yaml

It might not be related to this issue, but it looks like here generate subcommand is missing.

@czechboy0
Copy link
Contributor

On the linker issue, does it reproduce after you clean your project?

On the second, can you please file that as a separate issue?

Thanks! 🙏

@simonjbeaumont
Copy link
Collaborator

simonjbeaumont commented Jun 9, 2023

@AliakseiM thanks for trying out the tutorial and sorry it didn't work for you.

I just followed the tutorial and I think there's a missing step.

Can you navigate to the target settings and in the Link Binary With Libraries section, click and add OpenAPIRuntime and OpenAPIURLSession?

If this resolves your issue, I will open a PR to the documentation.

It's also worth noting that, in section 3, the code is built up over multiple steps and requires you to get to the end of the section before the function is complete and the code compiles. This will be much more obvious though: at Step 3 of Section 3 we're not returning a string from the function yet.

@czechboy0 I think this step might have been missed because the tutorial didn't initially generate into a separate framework target, and it didn't seem to be a necessary step when we did everything in the single target project.

@czechboy0
Copy link
Contributor

Thanks for getting to the bottom of this, @simonjbeaumont. Let's fix the docs, once @AliakseiM confirms that it works with that step added. 🙂

@czechboy0 czechboy0 added area/documentation Improvements or additions to documentation. kind/bug Feature doesn't work as expected. size/S Small task. (A couple of hours of work.) labels Jun 9, 2023
@AliakseiM
Copy link
Author

Hi @simonjbeaumont, it worked for me.

Thank you, guys for your help and your work!

@simonjbeaumont
Copy link
Collaborator

Actually @AliakseiM I just went through the tutorial again and I think there's a subtlety you potentially missed in this step:

Step 8
Repeat the same steps two more times, with the packages https://github.com/apple/swift-openapi-runtime and >https://github.com/apple/swift-openapi-urlsession.

This time do check the library products to be added to the GeneratedClient target.

Did you select the right target when adding the OpenAPIRuntime and OpenAPIURL libraries to your project?

image

The default won't be that target so needs manually changing. When I manually change them I am able to get away without updating the linking settings manually.

If that's the issue, it's pretty subtle (even I missed it when trying to reproduce your issue 😁)—we'll see if we can call it out clearer.

Could you confirm it resolves your issue 🙏

simonjbeaumont added a commit that referenced this issue Jun 9, 2023
### Motivation

In our Xcode tutorial we outline the steps to enable Swift OpenAPI
Generator on a separate framework. When you come to add the package
dependencies on the runtime and transport libraries the default target
Xcode offers to add them to is not this new framework. Failing to add
them to the framework target causes linker issues.

This is implied in our guide but it's pretty subtle and a user tripped
up over this.

### Modifications

- Emphasize which target the libraries need to be added to in the Xcode
tutorial.

### Result

Hopefully clearer step in the tutorial. 

### Test Plan

Ran through the steps manually and confirmed this generates a building
app.

### Resolves

Resolves #57.

Signed-off-by: Si Beaumont <[email protected]>
@simonjbeaumont
Copy link
Collaborator

Oops @AliakseiM I didn't mean to close this issue without confirming with you, but I merged the PR that referenced it. Let us know if you have any issues or if the above clarification resolved things for you.

@AliakseiM
Copy link
Author

@simonjbeaumont @czechboy0 I can confirm, that it works now. Sorry for my inattention.
Thans! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation Improvements or additions to documentation. kind/bug Feature doesn't work as expected. size/S Small task. (A couple of hours of work.)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants