Bazel - Can't compile without import Foundation, UIkit, - bazel

I'm trying to compile a swift project with Bazel, version 4.2.1.
I have a main project with multiple CocoaPods submodules of my own installed. I have a WORKSPACE and a BUILD configuration file for the project and another WORKSPACE and BUILD for each submodule.
I add the secondary workspaces as local_repository in the main workspace. I create the submodule build with a swift_library and add it in the main build in deps.
If in a .swift file, located in the submodule, I create a variable "var dateIni: Date?" I get an error "error: cannot find type Date in scope". I can solve this with "import Foundation" but xcode doesn't need it, I would like to be able to compile in Bazel without having to do these SDK frameworks imports. Is there any way to solve this?
I can post code or explain it better if you need more information.

Related

How to add Swift Package to DEBUG builds only?

How to add a dependency that only needs when building with Debug configuration?
Or better yet, how to exclude a Swift Package from Release configuration?
I tried to use EXCLUDED_SOURCE_FILE_NAMES build settings, but package sources are not directly linked.
You can create a Framework for debug libraries, and exclude the actual framework file from Release builds. ✨
Add the Swift Package to the project
Create a framework called DebugPackages
Add the Swift Package to the framework at General/Frameworks and Libraries
Add DebugPackages.framework to the Build Options/Excluded Source File Names build setting in Release configuration.

Module 'Swift' was created for incompatible target x86_64-apple-ios13.0

I'm creating an iOS framework and I want to copy some Xcode templates from my framework directory (that are not included in my .xcproject, but are in the folder that contains the project), when my framework is installed trought Cocoapods. In other words, when a developer installs my framework with Cocoapods or manually, I want to copy the templates into his Xcode Template Files folder.
I'm trying to execute a swift script file from the build phase of Xcode like this:
swift "${SRCROOT}/Folder/Folder/installer.swift"
But I get this error when I try to build it:
/<unknown>:1:1: module 'Swift' was created for incompatible target x86_64-apple-ios13.0: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/Swift.swiftmodule/x86_64.swiftmodule
If I execute swift installer.swift from the terminal, the script works. So, I think there is a problem with my Xcode.
My installer.swift file copies the template files to the Xcode Template Files folder.
I don't know if this way is the correct one, but I didn't find any other solution so far.
When I tried something similar I had to tell swift to compile for macOS by adding the following "shebang" comment as the first line of the swift script:
#!/usr/bin/env xcrun --sdk macosx swift

Save packages downloaded by SPM into project GIT using Xcode 11

I started using new Xcode 11 which integrates SPM.
I added first dependency to my project:
but detected that files are not fetched into my project folder but into Xcode's cache:
I would like to commit all my dependencies files into my main project repository so my question is:
Is it possible to change location of fetched packages via SPM using Xcode 11?
It's somewhat possible, although the solution isn't necessarily a good or great practice, so I can't recommend.
Set the DerivedData in workspace settings to be relative to the workspace.
Add gitignore rules such that the workspace/WORKSPACE_NAME_DIR/SourcePackages/checkouts and related files are includes. Maybe best to ensure repositories directory is not included.
Add a Run Script phase to remove .git and .gitignore files in the checkouts directory.
Obviously, this is fragile largely through fighting the way SPM works. The workspace settings are per person so it's not great in teams.
SwiftPM integration has been setup to prevent this. It clones the files into a DerivedData/ProjectName-[RandomStuff]. You should commit your Package.resolved into the repo to ensure that you get the same version of each dependency across clones of the project.

Xcode SwiftGen: build fails in project with multiple targets

How should I configure SwiftGen when using Cocoapods and multiple targets?
I have a project with two targets (MyProject and MyProject Dev) which has SwiftGen integrated with Cocoapods.
I can build the first target with no problems whatsoever. However the 'Dev' target always fails. The script phase is the last step in Build Phases, however running it earlier or later seems to make no difference.
On failure, I've observed the following:
The generated .swift file has an import statement, 'import MyProject' which shouldn't be there
'No type named [ClassName] in module [MyProject]' OR 'No such module [MyProject]'
SwiftGen version I'm using is 5.2.1
Xcode 9.2, targeting iOS 10.0
SwiftGen from version 5 onwards requires a configuration file, so I've set one up as follows:
output_paths: Sources/Generated
storyboards:
- paths: MyProject/Storyboards/Base.lproj
templateName: swift4
output: MyProject/Storyboards/Storyboards.swift
params:
ignoreTargetModule: true
So far I've looked up documentation and the following issue:
https://github.com/SwiftGen/SwiftGen/issues/273
However the difference is that I'm using a different type of SG installation and my project fails to build (rather than simply not generating any resources)
Cleaning project, build folder and deleting derived data had no effect. I'm assuming that I may have missed something in configuration setup, but I can't see what that would be.
First question on here, so apologies if I missed something, will be happy to edit.
I had the same issue with generating Storyboard file. Try to modify your config file:
params:
ignoreTargetModule: true
module: <YOUR_PROJECT_NAME>
Hope it will help.
Hesitant to call this a solution, it's more of a workaround, but the following approach has at least allowed the projects to be built and run.
Remove the SwiftGen script phase from the 'Dev' target
Build the project using the main scheme that includes SwiftGen to generate all the necessary objects and constructs
Switch to Dev scheme and run the project.
The Strings.swift file created by SwiftGen is linked to both targets, so even after running the script in one scheme the resources within that file will be available to both regular and Dev targets.
Hope this helps someone.

Facebook iOS SDK 3.1 from Github missing FacebookSDK.framework

I want to use Facebook SDK on XCode 4.5 for integration with iOS6.
I read this tutorial. I was using this .dmg package to install the library but I need to track and read the implementation of some methods, so I noticed that there is a repo on Github with the current source code.
My problem is that I don't know how to install this properly as with the package .dmg. Any ideas on how to do it? I tried to just import the src folder and reference the whole project but I'm having a lot of issues, warnings and errors.
Update
I had to do this again, so now I made it work. Here is what I did:
I tried both ways, building the source code (1) and importing the files directly(2). On the first scenario it was easy, on the root folder of Github repo just run:
sudo scripts/build_framework.sh
You will get the files needed, the same that you get when installing with .pkg. But I needed to track the functions, so I tried to importing the files.
First I added the src folders from the Github repo on my project. I had an issue with duplicated definitions on every file. The problem was on my Build Settings (BS), I was still referencing to the .pkg install directory of Facebook so I had the files duplicated. I removed every reference to that folder on BS and then added the files.
After that, on the files that imported the Facebook files I got:
Undefined symbols for architecture i386
When I copied the files to XCode, the .m files where not automatically added to the Build Phases / Compile Sources. I added them manually and imported FBConnect.h on my files.
Hope it helps some one with the same issue.
If you include the FacebookSDK via git, you will need to build the framework. Run the following command from within the FacebookSDK directory:
scripts/build_framework.sh
Then, FacebookSDK.framework will appear in FacebookSDK/build
Add the entire src folder to your project. Import FBConnect.h in any class where you want to use Facebook. The connect class imports the rest of the necessary classes.
#import "FBConnect.h"

Resources