Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/mixed-test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
)
22 changes: 22 additions & 0 deletions examples/mixed-test/ObjcFile.h
Original file line number Diff line number Diff line change
@@ -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 <Foundation/Foundation.h>

@interface ObjcObject : NSObject

@property (strong, nonatomic) id someProperty;

- (void) someMethod;

@end

#endif /* objcHeader_h */
30 changes: 30 additions & 0 deletions examples/mixed-test/ObjcFile.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// objcFile.m
// mixed-test
//
// Created by Oscar Bonilla on 7/23/18.
// Copyright © 2018 Oscar Bonilla. All rights reserved.
//

#import <Foundation/Foundation.h>

#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

27 changes: 27 additions & 0 deletions examples/mixed-test/SwiftObj.swift
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs an import Foundation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that come from the Objective-C headers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Swift will pull in transitive modules like that?


@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()
}

}
5 changes: 5 additions & 0 deletions examples/mixed-test/mixed-test-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 6 additions & 3 deletions rules/library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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("""
Expand Down Expand Up @@ -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}"
Expand All @@ -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 <Foundation/Foundation.h>
Expand Down Expand Up @@ -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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should only normalize in the fallback case, i.e.

kwargs.pop("module_name", _normalize_module_name(name))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... good point. I'll change it.

namespace = module_name if namespace_is_module_name else name
module_map = kwargs.pop("module_map", None)
cc_copts = kwargs.pop("cc_copts", [])
Expand Down