mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 06:45:24 +00:00
Merge pull request #9501 from ziglang/macho-objc-cleanup
Add standalone Objective-C enabled on macOS only
This commit is contained in:
commit
eba153f88f
@ -1471,6 +1471,7 @@ fn sortSections(self: *MachO) !void {
|
||||
&self.cstring_section_index,
|
||||
&self.ustring_section_index,
|
||||
&self.text_const_section_index,
|
||||
&self.objc_methlist_section_index,
|
||||
&self.objc_methname_section_index,
|
||||
&self.objc_methtype_section_index,
|
||||
&self.objc_classname_section_index,
|
||||
|
||||
@ -37,6 +37,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
|
||||
if (std.Target.current.os.tag == .linux) {
|
||||
cases.addBuildFile("test/standalone/pie/build.zig", .{});
|
||||
}
|
||||
// Try to build and run an Objective-C executable.
|
||||
if (std.Target.current.os.tag == .macos) {
|
||||
cases.addBuildFile("test/standalone/objc/build.zig", .{ .build_modes = true });
|
||||
}
|
||||
|
||||
// Ensure the development tools are buildable.
|
||||
cases.add("tools/gen_spirv_spec.zig");
|
||||
|
||||
7
test/standalone/objc/Foo.h
Normal file
7
test/standalone/objc/Foo.h
Normal file
@ -0,0 +1,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface Foo : NSObject
|
||||
|
||||
- (NSString *)name;
|
||||
|
||||
@end
|
||||
11
test/standalone/objc/Foo.m
Normal file
11
test/standalone/objc/Foo.m
Normal file
@ -0,0 +1,11 @@
|
||||
#import "Foo.h"
|
||||
|
||||
@implementation Foo
|
||||
|
||||
- (NSString *)name
|
||||
{
|
||||
NSString *str = [[NSString alloc] initWithFormat:@"Zig"];
|
||||
return str;
|
||||
}
|
||||
|
||||
@end
|
||||
22
test/standalone/objc/build.zig
Normal file
22
test/standalone/objc/build.zig
Normal file
@ -0,0 +1,22 @@
|
||||
const std = @import("std");
|
||||
const Builder = std.build.Builder;
|
||||
|
||||
pub fn build(b: *Builder) void {
|
||||
const mode = b.standardReleaseOptions();
|
||||
const target = b.standardTargetOptions(.{});
|
||||
|
||||
const test_step = b.step("test", "Test the program");
|
||||
|
||||
const exe = b.addExecutable("test", null);
|
||||
b.default_step.dependOn(&exe.step);
|
||||
exe.addIncludeDir(".");
|
||||
exe.addCSourceFile("Foo.m", &[0][]const u8{});
|
||||
exe.addCSourceFile("test.m", &[0][]const u8{});
|
||||
exe.setBuildMode(mode);
|
||||
exe.setTarget(target);
|
||||
exe.linkLibC();
|
||||
exe.linkFramework("Foundation");
|
||||
|
||||
const run_cmd = exe.run();
|
||||
test_step.dependOn(&run_cmd.step);
|
||||
}
|
||||
12
test/standalone/objc/test.m
Normal file
12
test/standalone/objc/test.m
Normal file
@ -0,0 +1,12 @@
|
||||
#import "Foo.h"
|
||||
#import <assert.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@autoreleasepool {
|
||||
Foo *foo = [[Foo alloc] init];
|
||||
NSString *result = [foo name];
|
||||
assert([result isEqualToString:@"Zig"]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user