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

3rd Party Swift framework imported in Tweak.xm, but not in Swift source files #58

Closed
matteo-pacini opened this issue Jun 1, 2019 · 7 comments · Fixed by theos/theos#538

Comments

@matteo-pacini
Copy link

matteo-pacini commented Jun 1, 2019

Hello there,
I'm experiencing issues with 3rd party Swift frameworks.

The framework under test is a 3rd party Swift framework called: QuickTableViewController.

This is my directory layout:
Screenshot 2019-06-01 at 07 58 57

And this is my Makefile:

TARGET = iphone:latest:10.0:12.2
ARCHS = armv7 arm64
MODULES = jailed
include $(THEOS)/makefiles/common.mk

TWEAK_NAME = instap4tch0
DISPLAY_NAME = InstaP4tch0
BUNDLE_ID = it.codecraft.instap4tch0

instap4tch0_FILES = Tweak.xm $(wildcard lib/*.swift)
instap4tch0_IPA = ../Instagram.ipa
instap4tch0_CFLAGS = -fobjc-arc
instap4tch0_FRAMEWORKS = Foundation UIKit QuickTableViewController
instap4tch0_EMBED_FRAMEWORKS = QuickTableViewController.framework
instap4tch0_USE_FLEX = 1

include $(THEOS_MAKE_PATH)/tweak.mk

The Swift framework can correctly be imported in Tweak.xm...

#import <QuickTableViewController/QuickTableViewController-Swift.h>

... but I cannot use it from any of the Swift files inside lib.

It looks like the framework flags are ignored when compiling Swift files (?)

Screenshot 2019-06-01 at 08 01 59

Any idea on how to fix this?

Thanks, keep up the great work!

@kabiroberai
Copy link
Owner

I haven't used Swift frameworks with Theos before, but it should work if you do instap4tch0_SWIFTFLAGS = -F. -framework QuickTableViewController

@matteo-pacini
Copy link
Author

It fails - it looks like those flags are getting ignored for some reason - (?)

I added this line in instance/rules.mk:

_THEOS_INTERNAL_SWIFTFLAGS += -F. $(patsubst %.framework,-framework %,$(notdir $(EMBED_FRAMEWORKS)))

This makes it compile - just tested on the device, it also does the right thing when invoking code from the library.

@kabiroberai
Copy link
Owner

Could you remove that line from instance/rules.mk and tell me the output of make clean all messages=yes?

@matteo-pacini
Copy link
Author

@kabiroberai
Here's the config:

instap4tch0_CFLAGS = -fobjc-arc -FFrameworks
instap4tch0_LDFLAGS = -FFrameworks
instap4tch0_EMBED_FRAMEWORKS = $(wildcard Frameworks/*.framework)
instap4tch0_SWIFTFLAGS = -FFrameworks

And the output of the requested command:

(printf "\e[0;3%im==> \e[1;39m%s…\e[m\n" 6 "Cleaning"); set -o pipefail; (rm -rf "/Users/zi0p4tch0/Desktop/instap4tch0/.theos/obj")
==> Cleaning…
set -o pipefail; (rm "/Users/zi0p4tch0/Desktop/instap4tch0/.theos/build_session")
set -o pipefail; (touch "/Users/zi0p4tch0/Desktop/instap4tch0/.theos/build_session")
set -o pipefail; (rm -rf "/Users/zi0p4tch0/Desktop/instap4tch0/.theos/_")
> Making all for tweak instap4tch0…
/Applications/Xcode-10.2.1.app/Contents/Developer/usr/bin/make -f Makefile --no-keep-going COLOR=1 \
		internal-library-compile \
		_THEOS_CURRENT_TYPE=tweak THEOS_CURRENT_INSTANCE=instap4tch0 _THEOS_CURRENT_OPERATION=compile \
		THEOS_BUILD_DIR="." _THEOS_MAKE_PARALLEL=yes
/Applications/Xcode-10.2.1.app/Contents/Developer/usr/bin/make -f Makefile --no-print-directory --no-keep-going internal-tweak-compile _THEOS_CURRENT_TYPE="tweak" THEOS_CURRENT_INSTANCE="instap4tch0" _THEOS_CURRENT_OPERATION="compile" THEOS_BUILD_DIR="." THEOS_CURRENT_ARCH="armv7"
set -o pipefail; (mkdir -p /Users/zi0p4tch0/Desktop/instap4tch0/.theos/obj/debug/armv7/lib/)
(printf "\e[0;3%im==> \e[1;39m%s…\e[m\n" 2 "Compiling lib/Bundle+InstaP4tch0.swift (armv7)"); set -o pipefail; (/Applications/Xcode-10.2.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -emit-object -emit-module -c -I/Users/zi0p4tch0/Repositories/theos/include -I/Users/zi0p4tch0/Repositories/theos/vendor/include -I/Users/zi0p4tch0/Repositories/theos/include/_fallback -import-objc-header instap4tch0-Bridging-Header.h -emit-dependencies-path "/Users/zi0p4tch0/Desktop/instap4tch0/.theos/obj/debug/armv7/lib/Bundle+InstaP4tch0.swift.ec40a17c.Td" -color-diagnostics -DTHEOS_SWIFT -DTARGET_IPHONE  -module-name instap4tch0 -g -sdk "/Users/zi0p4tch0/Repositories/theos/sdks/iPhoneOS12.2.sdk"    -DDEBUG -Onone -target armv7-apple-ios10.0 -emit-module-path /Users/zi0p4tch0/Desktop/instap4tch0/.theos/obj/debug/armv7/lib/Bundle+InstaP4tch0.swift.ec40a17c.swiftmodule -primary-file lib/Bundle+InstaP4tch0.swift lib/Bundle+Localisation.swift lib/Bundle+Versioning.swift lib/Downloader+Photos.swift lib/Downloader.swift lib/Feature.swift lib/PostType.swift lib/SettingsViewController.swift lib/UIAlertController+GenericActions.swift lib/UIAlertController+LikeGuard.swift lib/UIAlertController+Utils.swift lib/UIImage+Resources.swift -o /Users/zi0p4tch0/Desktop/instap4tch0/.theos/obj/debug/armv7/lib/Bundle+InstaP4tch0.swift.ec40a17c.o)
==> Compiling lib/Bundle+InstaP4tch0.swift (armv7)…
/Users/zi0p4tch0/Desktop/instap4tch0/./instap4tch0-Bridging-Header.h:1:9: error: 'MBProgressHUD/MBProgressHUD.h' file not found
#import <MBProgressHUD/MBProgressHUD.h>
        ^
<unknown>:0: error: failed to import bridging header 'instap4tch0-Bridging-Header.h'
make[3]: *** [/Users/zi0p4tch0/Desktop/instap4tch0/.theos/obj/debug/armv7/lib/Bundle+InstaP4tch0.swift.ec40a17c.swiftmodule] Error 1
make[2]: *** [/Users/zi0p4tch0/Desktop/instap4tch0/.theos/obj/debug/armv7/instap4tch0.dylib] Error 2
make[1]: *** [internal-library-all_] Error 2
make: *** [instap4tch0.all.tweak.variables] Error 2```

@kabiroberai
Copy link
Owner

This appears to be a different issue. You might need to specify an include path to resolve it. Try -IFrameworks in both your swiftflags and ldflags, or alternatively include it via its relative path: "Frameworks/MBProgressHUD/MBProgressHUD.h"

@Mamong
Copy link

Mamong commented Apr 1, 2020

depend on swift runtime, and add a swift file will fix your problem.

@kabiroberai
Copy link
Owner

For what it's worth, <instance>_SWIFTFLAGS not being recognised was in fact a Theos bug which I've fixed in an experimental branch – see theos/theos@51191e3#diff-da6b63ee07632eb99d4e7575a46e968bR136. Once that's merged, it'll be possible to do this the "correct" way using <instance>_SWIFTFLAGS rather than _THEOS_INTERNAL_SWIFTFLAGS.

This issue was 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

Successfully merging a pull request may close this issue.

4 participants
@matteo-pacini @Mamong @kabiroberai and others