How to expose an Objective-C Module properly using Bazel? - swift

I'm trying to build RxSwift using Bazel in order to be able to use it in a dummy project as a dependency, for the sake of getting to know it a bit.
We don't use the latest RxSwift version at the moment, but version 4.4.2.
After reading through the docs, I've come to the point where I successfully add the specific release to my workspace as an http_archive, and supply my own BUILD file to build that external dependency RxSwift.
You can check out the BUILD file and WORKSPACE file here:
https://gist.github.com/daneov/487444109c703087862d830a3445ee86
Running
bazel build #rx_swift//:RxSwift
yields a Swift compilation error:
No such module: RxAtomic
So, this shows that my I'm missing something with regards to exposing the Objective-C module to a Swift library.
I currently supply these options to the objc_framework:
enable_modules = 1,
alwayslink = 1,
module_name = "RxAtomic"
Thanks in advance for any thoughts/pointers!

You should call bazel build with --experimental_objc_enable_module_maps option

Related

Swift Package Manager (package successfully added, but Module not found)

I'm new in Swift. I want to create iOS app that can connect to PostgreSQL database. First I found library https://github.com/vapor/postgresql.git that should be added to my project via Swift Package Manager. Using tutorial I added required library to my project successfully (File -> Swift Packages -> Add Package Dependency):
list of added packages from SPM
But when I try to import this module into my view controller, Xcode shows error that module is not found:
not found
I tried several times to rebuild my project, created new project just for testing this issue. Also I found information about build phases and added this lib as a dependency:
build phases
But I still get error: "No such module PostgreSQL".
Can anyone help me?
I found solution by myself. I compiled C static library "libpq" (can be found in PostgreSQL sources) and added it to my swift project. Included this library by adding special bridging header file. Finally I got what I wanted.
P.S. If someone what to repeat, he or she should know: static C library must be compiled for iOS device architecture (and also in iOS simulator architecture which differs from iOS device arch.).

Local swift package with local dependency

I have a project that I plan on developing in modules, the final application will be any number of the modules built together based on a configuration. I have a swift package that has all of my common code it it, we can call that the platform package. I then went to create my first feature, this went just fine however when I created the wrapper application to pull in each feature, I got this error from SPM in xcode11:
package 'Platform' is required using a revision-based requirement and it depends on local package
'Feature1', which is not supported.
Looking at the code base for SPM here (line 72)
https://github.com/apple/swift-package-manager/blob/master/Sources/PackageGraph/DependencyResolver.swift
It looks like this is something that is just not supported, the mixing of local and remote dependencies? Is this a limitation of SPM / should I be trying to use another tool for this type of app architecture?
In my case, I was trying to add a package, which I was developing, and its Package.swift contained dependencies of the form:
dependencies: [
.package(path: "../PackageName"),
// etc
Changing the references to specific repos solved the problem:
dependencies: [
.package(path: "http://github.com/..."),
// etc

Can't build command line project with SQLite.swift

I'm trying to build a command-line tool which uses sqlite. I have downloaded Stephen Celis' swift wrapper, SQLite.swift, and built a working OS X app. However, I am not able to build my command-line tool. I believe that I correctly followed the instructions to do so in the SQLite.swift Documentation for frameworkless targets, but apparently I am missing something. I get an error in Helper.swift # import CSQLite -> No such module 'CSQLite'.
I am linking against libsqlite3.dylib (also tried libsqlite3.tbd)
I added the SQLite.swift source to my project
I added #import sqlite3.h & #import "SQLite-Bridging.h" to my bridging header file. Perhaps of note, when I right-click on sqlite3.h or SQLite-Bridging.h, xCode does not know where/what they are.
I'm happy to send my test project (about 80KB, compressed) to anyone who can and is willing to help. There is probably a very simple solution, I just do not see what it is.
thx for any help,
-Craig
I've faced the same problem.
There were lots of compiler errors like "Connection.swift:26:8: Could not build Objective-C module 'CSQLite'"
The error has roots to the "lctx.h:13:25: Use of undeclared identifier 'SYS_getlcid'"
It worth mentioning that I have two Xcodes installed - v 6.2 at /Applications and v 7.3 at ~/Applications. My project is iOS app on Swift with SQLite pod and I open it with the Xcode 7.3.
The SQLite pod has a file at project_folder/Pods/SQLite.swift/CocoaPods/iphonesimulator/module.modulemap.
The file had the content
module CSQLite [system] {
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/sqlite3.h"
export *
}
To fix compiler errors I changed the content of module.modulemap to
module CSQLite [system] {
header "/Users/my_user_name/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/sqlite3.h"
export *
}
The change is that I pointed search of sqlite3.h into my ~/Applications folder where Xcode 7.3 is located.
This made my project compiling.

How to add *junit* to *spec.libraries* in generated podspec?

I am using the Gradle J2ObjC plugin to translate Java code in the pure-Java modules of my project to Objective-C. I have a need for the generated podspec file in the build/j2objcOutputs folder of one of my Java modules to contain a junit entry in the spec.libraries list. Currently it is defined as follows:
spec.libraries = 'ObjC', 'guava', 'javax_inject', 'jre_emul', 'jsr305', 'z', 'icucore'
Is there something that I can add to the build.gradle file of my Java module to make this possible?
I have been unable to figure out how to do this with the J2Objc Gradle plugin and have had to resort to putting the following in the "Other linker flags" in Xcode for my tests target:
$(inherited)
-l"junit"
I'm marking this as the solution until someone can suggest otherwise.

Unknown globals when installing ZXing Scanner

I have a Xamarin.Forms project which needs a QR code scanner. I found ZXing Scanner which seems to be a well established library for such purposes.
I installed it in the corresponding android project which worked without errors. When I wanted to build the app, Resource.Designer.cs was adjusted with the following lines:
global::ZXing.Mobile.Resource.Id.contentFrame = global::my.project.Droid.Resource.Id.contentFrame;
global::ZXing.Mobile.Resource.Layout.zxingscanneractivitylayout = global::my.project.Droid.Resource.Layout.zxingscanneractivitylayout;
global::ZXing.Mobile.Resource.Layout.zxingscannerfragmentlayout = global::my.project.Droid.Resource.Layout.zxingscannerfragmentlayout;
The problem is that I as well get the following errors:
'my.project.Droid.Resource.Id' does not contain a definition for 'contentFrame'
'my.project.Droid.Resource.Layout' does not contain a definition for 'zxingscanneractivitylayout'
'my.project.Droid.Resource.Layout' does not contain a definition for 'zxingscannerfragmentlayout'
I installed ZXing using NuGet but I as well tried to add the dlls manually. I get the same errors. Can anyone help me how to fix this?
Thank you in advance.
It's quite possible that your Resource.Designer.cs is not updating correctly:
Clean Project Build
Remove ZXing package.
Clean Project Build
Add ZXing package
Clean and Build Project once again
If it won't help:
https://kb.xamarin.com/customer/portal/articles/1638018-my-android-resource-designer-cs-file-will-not-update or https://forums.xamarin.com/discussion/13339/resource-designer-cs-not-regenerated/