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

Add support for .swift file for xcode #1477

Merged
Merged
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
88 changes: 88 additions & 0 deletions modules/xcode/tests/test_xcode_project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@
]]
end

function suite.PBXBuildFile_ListsSwiftSources()
files { "source.swift", "Info.plist" }
prepare()
xcode.PBXBuildFile(tr)
test.capture [[
/* Begin PBXBuildFile section */
4616E7383FD8A3AA79D7A578 /* source.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B2BDAE0539CBF12983B9120 /* source.swift */; };
/* End PBXBuildFile section */
]]
end

function suite.PBXBuildFile_ListsResourceFilesOnlyOnceWithGroupID()
files { "English.lproj/MainMenu.xib", "French.lproj/MainMenu.xib" }
prepare()
Expand Down Expand Up @@ -3563,6 +3574,83 @@
]]
end

function suite.XCBuildConfigurationProject_OnSwift4_0()
workspace("MyWorkspace")
swiftversion("4.0")
prepare()
xcode.XCBuildConfiguration_Project(tr, tr.configs[1])
test.capture [[
A14350AC4595EE5E57CE36EC /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(NATIVE_ARCH_ACTUAL)";
CONFIGURATION_BUILD_DIR = "$(SYMROOT)";
CONFIGURATION_TEMP_DIR = "$(OBJROOT)";
GCC_OPTIMIZATION_LEVEL = 0;
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
OBJROOT = obj/Debug;
ONLY_ACTIVE_ARCH = NO;
SWIFT_VERSION = 4.0;
SYMROOT = bin/Debug;
};
name = Debug;
};
]]
end

function suite.XCBuildConfigurationProject_OnSwift4_2()
workspace("MyWorkspace")
swiftversion("4.2")
prepare()
xcode.XCBuildConfiguration_Project(tr, tr.configs[1])
test.capture [[
A14350AC4595EE5E57CE36EC /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(NATIVE_ARCH_ACTUAL)";
CONFIGURATION_BUILD_DIR = "$(SYMROOT)";
CONFIGURATION_TEMP_DIR = "$(OBJROOT)";
GCC_OPTIMIZATION_LEVEL = 0;
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
OBJROOT = obj/Debug;
ONLY_ACTIVE_ARCH = NO;
SWIFT_VERSION = 4.2;
SYMROOT = bin/Debug;
};
name = Debug;
};
]]
end

function suite.XCBuildConfigurationProject_OnSwift5_0()
workspace("MyWorkspace")
swiftversion("5.0")
prepare()
xcode.XCBuildConfiguration_Project(tr, tr.configs[1])
test.capture [[
A14350AC4595EE5E57CE36EC /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(NATIVE_ARCH_ACTUAL)";
CONFIGURATION_BUILD_DIR = "$(SYMROOT)";
CONFIGURATION_TEMP_DIR = "$(OBJROOT)";
GCC_OPTIMIZATION_LEVEL = 0;
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
OBJROOT = obj/Debug;
ONLY_ACTIVE_ARCH = NO;
SWIFT_VERSION = 5.0;
SYMROOT = bin/Debug;
};
name = Debug;
};
]]
end

---------------------------------------------------------------------------
-- XCBuildConfigurationList tests
Expand Down
16 changes: 14 additions & 2 deletions modules/xcode/xcode_common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
[".icns"] = "Resources",
[".s"] = "Sources",
[".S"] = "Sources",
[".swift"] = "Sources",
}
if node.isResource then
return "Resources"
Expand Down Expand Up @@ -140,7 +141,7 @@
[".bmp"] = "image.bmp",
[".wav"] = "audio.wav",
[".xcassets"] = "folder.assetcatalog",

[".swift"] = "sourcecode.swift",
}
return types[path.getextension(node.path)] or "text"
end
Expand Down Expand Up @@ -1262,7 +1263,16 @@
end
end


function xcode.XCBuildConfiguration_SwiftLanguageVersion(settings, cfg)
-- if no swiftversion is provided, don't set swift version
-- Projects with swift files but without swift version will refuse
-- to build on Xcode but setting a default SWIFT_VERSION may have
-- unexpected interactions with other systems like cocoapods
if cfg.swiftversion then
settings['SWIFT_VERSION'] = cfg.swiftversion
end
end

function xcode.XCBuildConfiguration_Project(tr, cfg)
local settings = {}

Expand Down Expand Up @@ -1430,6 +1440,8 @@
settings['WARNING_CFLAGS'] = '-Weverything'
end

xcode.XCBuildConfiguration_SwiftLanguageVersion(settings, cfg)

xcode.overrideSettings(settings, cfg.xcodebuildsettings)

_p(2,'%s /* %s */ = {', cfg.xcode.projectid, cfg.buildcfg)
Expand Down
11 changes: 11 additions & 0 deletions src/_premake_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,17 @@
}
}

api.register {
name = "swiftversion",
scope = "config",
kind = "string",
allowed = {
"4.0",
"4.2",
"5.0",
}
}

api.register {
name = "libdirs",
scope = "config",
Expand Down