diff --git a/examples/mixed-test/BUILD.bazel b/examples/mixed-test/BUILD.bazel new file mode 100644 index 00000000..5bdeaa20 --- /dev/null +++ b/examples/mixed-test/BUILD.bazel @@ -0,0 +1,15 @@ +load("@build_bazel_rules_ios//rules:app.bzl", "ios_application") + +ios_application( + name = "mixed-test", + srcs = glob([ + "*.swift", + "*.m", + "*.h", + ]), + bundle_id = "com.example.mixed-app", + families = [ + "iphone", + ], + minimum_os_version = "12.0", +) diff --git a/examples/mixed-test/ObjcFile.h b/examples/mixed-test/ObjcFile.h new file mode 100644 index 00000000..8cb17abd --- /dev/null +++ b/examples/mixed-test/ObjcFile.h @@ -0,0 +1,22 @@ +// +// objcHeader.h +// mixed-test +// +// Created by Oscar Bonilla on 7/23/18. +// Copyright © 2018 Oscar Bonilla. All rights reserved. +// + +#ifndef objcHeader_h +#define objcHeader_h + +#import + +@interface ObjcObject : NSObject + +@property (strong, nonatomic) id someProperty; + +- (void) someMethod; + +@end + +#endif /* objcHeader_h */ diff --git a/examples/mixed-test/ObjcFile.m b/examples/mixed-test/ObjcFile.m new file mode 100644 index 00000000..758d627a --- /dev/null +++ b/examples/mixed-test/ObjcFile.m @@ -0,0 +1,30 @@ +// +// objcFile.m +// mixed-test +// +// Created by Oscar Bonilla on 7/23/18. +// Copyright © 2018 Oscar Bonilla. All rights reserved. +// + +#import + +#import "ObjcFile.h" +#import "mixed_test-Swift.h" + +@implementation ObjcObject + +- (void) someMethod { + NSLog(@"SomeMethod Ran"); +} + +- (void) someOtherMethod { + SwiftObj *myOb = [SwiftObj new]; + NSLog(@"myOb.someProperty: %@", myOb.someProperty); + myOb.someProperty = @"Hello World"; + NSLog(@"MyOb.someProperty: %@", myOb.someProperty); + NSString * retString = [myOb someFunctionWithSomeArg:@"Arg"]; + NSLog(@"RetString: %@", retString); +} + +@end + diff --git a/examples/mixed-test/SwiftObj.swift b/examples/mixed-test/SwiftObj.swift new file mode 100644 index 00000000..06bf15a8 --- /dev/null +++ b/examples/mixed-test/SwiftObj.swift @@ -0,0 +1,27 @@ +// +// mixed_test.swift +// mixed-test +// +// Created by Oscar Bonilla on 7/23/18. +// Copyright © 2018 Oscar Bonilla. All rights reserved. +// + +public class SwiftObj : NSObject { + + @objc public var someProperty: NSString = "Some Initializer Val" + + override init() {} + + @objc public func someFunction(someArg:AnyObject) -> String { + let returnVal = "You sent me \(someArg)" + return returnVal + } + + func someOtherFunction() { + let objcObject: ObjcObject = ObjcObject() + objcObject.someProperty = "Hello World" + print(objcObject.someProperty!) + objcObject.someMethod() + } + +} diff --git a/examples/mixed-test/mixed-test-Bridging-Header.h b/examples/mixed-test/mixed-test-Bridging-Header.h new file mode 100644 index 00000000..32223ed5 --- /dev/null +++ b/examples/mixed-test/mixed-test-Bridging-Header.h @@ -0,0 +1,5 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#import "ObjcFile.h" diff --git a/rules/library.bzl b/rules/library.bzl index 1ac9d73a..382dcc3c 100644 --- a/rules/library.bzl +++ b/rules/library.bzl @@ -47,6 +47,9 @@ write_file = rule( doc = "Writes out a file verbatim", ) +def _normalize_module_name(name): + return name.replace("-", "_") + def _extend_modulemap_impl(ctx): args = ctx.actions.args() args.add(""" @@ -90,7 +93,7 @@ def write_modulemap(name, library_tools, umbrella_header = None, public_headers basename = "{}.modulemap".format(name) destination = paths.join(name + "-modulemap", basename) if not module_name: - module_name = name + fail("module_name not set, this is a bug, please file an issue at https://github.com/ob/rules_ios/issues") content = """\ module {module_name} {{ umbrella header "{umbrella_header}" @@ -117,7 +120,7 @@ def write_umbrella_header(name, library_tools, public_headers = [], private_head basename = "{name}-umbrella.h".format(name = name) destination = paths.join(name + "-modulemap", basename) if not module_name: - module_name = name + fail("module_name not set, this is a bug, please file an issue at https://github.com/ob/rules_ios/issues") content = """\ #ifdef __OBJC__ # import @@ -243,7 +246,7 @@ def apple_library(name, library_tools = {}, export_private_headers = True, names else: fail("Unable to compile %s in apple_framework %s" % (f, name)) - module_name = kwargs.pop("module_name", name) + module_name = _normalize_module_name(kwargs.pop("module_name", name)) namespace = module_name if namespace_is_module_name else name module_map = kwargs.pop("module_map", None) cc_copts = kwargs.pop("cc_copts", [])