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

Error adding "apple_core_data_model" dependency to "swift_library" #1160

Closed
cs2be opened this issue Jan 24, 2024 · 14 comments
Closed

Error adding "apple_core_data_model" dependency to "swift_library" #1160

cs2be opened this issue Jan 24, 2024 · 14 comments

Comments

@cs2be
Copy link

cs2be commented Jan 24, 2024

Hi, I'm trying to add core data build dependencies to my swift project, however I got an error when trying to run the build rule:

apple_core_data_model(
   name = "coreDataModel",
   srcs = ["//Resources:CoreDataModel.xcdatamodeld"]
)

swift_library(
    name = "lib",
    srcs = glob(["Sources/**/*.swift"]),
    deps = [
        ":coreDataModel"
    ]
)

Running "bazel build //:lib", I get the following errors:

ChatGPTDemoiOS cs2be$ bazel build //:lib
ERROR: /Users/cs2be/programming/chatgpt_demo/ChatGPTDemoiOS/BUILD:24:14: in deps attribute of swift_library rule //:lib: '//:coreDataModel' does not have mandatory providers: 'CcInfo' or 'SwiftInfo' or 'objc'
ERROR: /Users/cs2be/programming/chatgpt_demo/ChatGPTDemoiOS/BUILD:24:14: Analysis of target '//:lib' failed
ERROR: Analysis of target '//:lib' failed; build aborted
INFO: Elapsed time: 0.092s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully

I suspect the build rule apple_core_data_model is missing SwiftInfo dictionary. The swift_library code that pulls SwiftInfo from deps is here.

I'm using these versions of rules_apple and rules_swift:

bazel_dep(name = "rules_apple", version = "3.2.1")
bazel_dep(name = "rules_swift", version = "1.15.1")

Thanks!

@keith
Copy link
Member

keith commented Jan 24, 2024

You want to put :coreDataModel in the srcs attribute instead, it doesn't produce a library it only generates source files

@cs2be
Copy link
Author

cs2be commented Jan 24, 2024

Thank you Keith, that worked and the core data swift files are now part of the project.

apple_core_data_model(
   name = "coreDataModel",
   srcs = ["//Resources:CoreDataModel.xcdatamodeld"]
)

swift_library(
    name = "lib",
    srcs = glob(["Sources/**/*.swift"]) + [":coreDataModel"],
    data = ["//Resources:CoreDataModel.xcdatamodeld"]
)

ios_application(
    name = "ChatGPTDemoApp",
    bundle_id = "com.midoriapple.ChatGPTDemoApp",
    families = [
        "iphone",
        "ipad",
    ],
    infoplists = ["Info.plist"],
    launch_storyboard = "//Resources:Launch.storyboard",
    minimum_os_version = "15.0",
    visibility = ["//visibility:public"],
    deps = [":lib"],
)

However, it seems there were some compile problems for those generated core data swift classes, wonder if you've seen this issue before? Thanks for your help!

cs2be$ bazel build //:ChatGPTDemoApp
INFO: Analyzed target //:ChatGPTDemoApp (1 packages loaded, 15 targets configured).
ERROR: /Users/cs2be/programming/chatgpt_demo/ChatGPTDemoiOS/BUILD:24:14: Compiling Swift module //:lib failed: (Exit 1): worker failed: error executing SwiftCompile command (from target //:lib) bazel-out/darwin_arm64-opt-exec-ST-13d3ddad9198/bin/external/rules_swift~1.13.0/tools/worker/worker swiftc ... (remaining 1 argument skipped)
remark: Incremental compilation has been disabled: ChatThread+CoreDataClass.swift has no swiftDeps file
remark: Incremental compilation has been disabled: ChatThread+CoreDataClass.swift has no swiftDeps file
remark: Incremental compilation has been disabled: malformed dependencies file 'none?!'
remark: Incremental compilation has been disabled: ChatThread+CoreDataProperties.swift has no swiftDeps file
remark: Incremental compilation has been disabled: ChatThread+CoreDataProperties.swift has no swiftDeps file
remark: Incremental compilation has been disabled: malformed dependencies file 'none?!'
remark: Incremental compilation has been disabled: CoreDataModel+CoreDataModel.swift has no swiftDeps file
remark: Incremental compilation has been disabled: CoreDataModel+CoreDataModel.swift has no swiftDeps file
remark: Incremental compilation has been disabled: malformed dependencies file 'none?!'
swift_worker: Could not copy bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min15.0-applebin_ios-ST-52085178dc52/bin/_swift_incremental/lib_objs/coredatamodel.coreDataModel.coredata.sources.o to bazel-out/ios_sim_arm64-fastbuild-ios-sim_arm64-min15.0-applebin_ios-ST-52085178dc52/bin/lib_objs/coredatamodel.coreDataModel.coredata.sources.o (No such file or directory)
Target //:ChatGPTDemoApp failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.061s, Critical Path: 0.94s
INFO: 2 processes: 2 internal.
ERROR: Build did NOT complete successfully

@keith
Copy link
Member

keith commented Jan 24, 2024

Interesting, I haven't seen this one, if you pass --swiftcopt=-wmo does it fix it?

@cs2be
Copy link
Author

cs2be commented Jan 24, 2024

Unfortunately no :(. I'll dig into this a little further, thanks for helping

cs2be$ bazel build //:ChatGPTDemoApp --swiftcopt=-wmo --verbose_failures
INFO: Analyzed target //:ChatGPTDemoApp (0 packages loaded, 0 targets configured).
ERROR: /Users/cs2be/programming/chatgpt_demo/ChatGPTDemoiOS/BUILD:24:14: output 'lib_objs/coredatamodel.coreDataModel.coredata.sources.o' was not created
ERROR: /Users/cs2be/programming/chatgpt_demo/ChatGPTDemoiOS/BUILD:24:14: Compiling Swift module //:lib failed: not all outputs were created or valid
Target //:ChatGPTDemoApp failed to build
INFO: Elapsed time: 0.605s, Critical Path: 0.50s
INFO: 2 processes: 1 internal, 1 worker.
ERROR: Build did NOT complete successfully

@keith
Copy link
Member

keith commented Jan 25, 2024

it seems like this must be a bug in the rules, if you provide a repro case someone might be able to debug further

@cs2be
Copy link
Author

cs2be commented Jan 25, 2024

That would be awesome. Here's how to reproduce:

git clone [email protected]:cs2be/chatgpt_demo.git
cd chatgpt_demo/ChatGPTDemoiOS
bazel build //:ChatGPTDemoApp --verbose_failures --subcommands --verbose_explanations

This should produce the error, thanks again!

@keith
Copy link
Member

keith commented Jan 25, 2024

Thanks for the repro, that is very helpful! Turns out the problem is the same as this: #969

@keith
Copy link
Member

keith commented Jan 25, 2024

A quick hack workaround is to pass --swiftcopt=-wmo --swiftcopt=-num-threads --swiftcopt=0 but this might have other downsides

@cs2be
Copy link
Author

cs2be commented Jan 25, 2024

Thanks Keith, I can confirm it works with those flags.

# Builds and runs on simulator
bazel run //:ChatGPTDemoApp --swiftcopt=-wmo --swiftcopt=-num-threads --swiftcopt=0 

However strange thing is the xcode project still doesn't compile :(. Possibly I need to pass another set of flags to this build? Should I close this issue as a duplicate? Thanks!

bazel run //:xcodeproj --swiftcopt=-wmo --swiftcopt=-num-threads --swiftcopt=0
Screenshot 2024-01-25 at 10 19 35 AM

@keith
Copy link
Member

keith commented Jan 25, 2024

Yea I think you'd have to pipe those flags to rules_xcodeproj too, you probably should just add them to your .bazelrc.

@keith keith closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2024
@xuzhaocheng
Copy link

xuzhaocheng commented Sep 5, 2024

Hi @keith , I am facing the same issue when I use the latest version of rule_apple and rule_swift.
The workaround --swiftcopt=-wmo --swiftcopt=-num-threads --swiftcopt=0 doesn't work anymore.

I forked @cs2be 's repo and created a new branch new to reproduce this issue.
Could you please help to take a look? Thanks

[email protected]:xuzhaocheng/chatgpt_demo.git
cd chatgpt_demo
git checkout new
cd ChatGPTDemoiOS
bazel build //:ChatGPTDemoApp --swiftcopt=-wmo --swiftcopt=-num-threads --swiftcopt=0 

@leohidalgo
Copy link

The latest rule versions where it worked was:

swift: 1.18.0
apple: 3.16.0

@xuzhaocheng
Copy link

Do we have any plan to fix this issue on swift 2.x?

@leohidalgo
Copy link

@xuzhaocheng maybe you could create a new issue since this one is closed

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

No branches or pull requests

4 participants