Skip to content

Commit

Permalink
Merge branch 'fix-missing-source-files-in-fastbuild-xcode-projects' i…
Browse files Browse the repository at this point in the history
…nto 'main'

Improvements for xcode fastbuild projects

See merge request Sharpmake/sharpmake!554
  • Loading branch information
jspelletier committed Sep 19, 2024
2 parents b7c5bf6 + 849ef79 commit e7ef130
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 17 deletions.
55 changes: 43 additions & 12 deletions Sharpmake.Generators/Apple/XCodeProj.Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,14 +518,48 @@ private static class Template
</BuildableReference>
</TestableReference>";

public static string SchemeFileTemplate =
/// <summary>
/// This section is used to configure the executable to run for native projects.
/// </summary>
public static string SchemeRunnableNativeProject =
@"
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = ""primary""
BlueprintIdentifier = ""[item.Uid]""
BuildableName = ""[item.OutputFile.BuildableName]""
BlueprintName = ""[item.Identifier]""
ReferencedContainer = ""container:[projectFile].xcodeproj"">
</BuildableReference>
</BuildableProductRunnable>";

/// <summary>
/// This section is used to configure the executable to run for makefile projects.
/// </summary>
public static string SchemeRunnableMakeFileProject =
@"
<PathRunnable
runnableDebuggingMode = ""0""
FilePath = ""[runnableFilePath]"">
</PathRunnable>";

/// <summary>
/// First part of schema file
/// </summary>
/// <remarks>
/// Schema files have the following format:
/// SchemeFileTemplatePart1
/// SchemeRunnableNativeProject OR SchemeRunnableMakeFileProject
/// SchemeFileTemplatePart2
/// </remarks>
public static string SchemeFileTemplatePart1 =
@"<?xml version=""1.0"" encoding=""UTF-8""?>
<Scheme
LastUpgradeVersion = ""0460""
version = ""1.3"">
<BuildAction
parallelizeBuildables = ""YES""
buildImplicitDependencies = ""YES"">
buildImplicitDependencies = ""[buildImplicitDependencies]"">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = ""YES""
Expand Down Expand Up @@ -561,16 +595,13 @@ private static class Template
debugDocumentVersioning = ""YES""
enableGPUFrameCaptureMode = ""[options.EnableGpuFrameCaptureMode]""
enableGPUValidationMode = ""[options.MetalAPIValidation]""
allowLocationSimulation = ""YES"">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = ""primary""
BlueprintIdentifier = ""[item.Uid]""
BuildableName = ""[item.OutputFile.BuildableName]""
BlueprintName = ""[item.Identifier]""
ReferencedContainer = ""container:[projectFile].xcodeproj"">
</BuildableReference>
</BuildableProductRunnable>[commandLineArguments]
allowLocationSimulation = ""YES"">";

/// <summary>
/// Secondpart of schema file
/// </summary>
public static string SchemeFileTemplatePart2 =
@"[commandLineArguments]
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand Down
26 changes: 21 additions & 5 deletions Sharpmake.Generators/Apple/XCodeProj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,30 @@ string projectFile
var defaultConfiguration = configurations.Where(conf => conf.UseAsDefaultForXCode == true).FirstOrDefault();
Project.Configuration activeConfiguration = defaultConfiguration != null ? defaultConfiguration : configurations[0];
string targetName = $"&quot;{activeConfiguration.Target.Name}&quot;";
string buildImplicitDependencies = activeConfiguration.IsFastBuild ? "NO" : "YES";
bool useBuildableProductRunnableSection = true;
string runnableFilePath = string.Empty;
if (activeConfiguration.IsFastBuild && activeConfiguration.Output == Project.Configuration.OutputType.AppleApp && !activeConfiguration.XcodeUseNativeProjectForFastBuildApp)
{
useBuildableProductRunnableSection = false;
runnableFilePath = Path.Combine(activeConfiguration.TargetPath, activeConfiguration.TargetFileFullNameWithExtension);
}

using (fileGenerator.Declare("projectFile", projectFile))
using (fileGenerator.Declare("item", defaultTarget))
using (fileGenerator.Declare("options", options))
using (fileGenerator.Declare("testableElements", testableElements))
using (fileGenerator.Declare("DefaultTarget", targetName))
using (fileGenerator.Declare("commandLineArguments", commandLineArguments))
using (fileGenerator.Declare("buildImplicitDependencies", buildImplicitDependencies))
using (fileGenerator.Declare("runnableFilePath", runnableFilePath))
{
fileGenerator.Write(Template.SchemeFileTemplate);
fileGenerator.Write(Template.SchemeFileTemplatePart1);
if (useBuildableProductRunnableSection)
fileGenerator.Write(Template.SchemeRunnableNativeProject);
else
fileGenerator.Write(Template.SchemeRunnableMakeFileProject);
fileGenerator.Write(Template.SchemeFileTemplatePart2);
}

// Remove all line that contain RemoveLineTag
Expand Down Expand Up @@ -497,7 +512,8 @@ private void PrepareSections(XCodeGenerationContext context, List<Project.Config

var firstConf = targetConfigurations.First();

if (!firstConf.IsFastBuild) // since we grouped all FastBuild conf together, we only need to test the first conf
bool canIncludeSourceFiles = !firstConf.IsFastBuild || firstConf.Output != Project.Configuration.OutputType.AppleApp || !firstConf.XcodeUseNativeProjectForFastBuildApp;
if (canIncludeSourceFiles)
{
var projectSourcesBuildPhase = new ProjectSourcesBuildPhase(xCodeTargetName, 2147483647);
_projectItems.Add(projectSourcesBuildPhase);
Expand Down Expand Up @@ -554,7 +570,7 @@ private void PrepareSections(XCodeGenerationContext context, List<Project.Config

foreach (var conf in targetConfigurations)
{
if (!conf.IsFastBuild)
if (canIncludeSourceFiles)
PrepareSourceFiles(xCodeTargetName, sourceFiles.SortedValues, project, conf, forUnitTest: false, workspacePath);

if (createUnitTestTarget)
Expand Down Expand Up @@ -721,7 +737,7 @@ private void PrepareSections(XCodeGenerationContext context, List<Project.Config

ProjectTarget target;
ProjectTarget targetUnitTest = null;
if (!firstConf.IsFastBuild || firstConf.Output == Project.Configuration.OutputType.AppleApp)
if (!firstConf.IsFastBuild || (firstConf.Output == Project.Configuration.OutputType.AppleApp && firstConf.XcodeUseNativeProjectForFastBuildApp))
{
target = new ProjectNativeTarget(xCodeTargetName, targetOutputFile, configurationListForNativeTarget, _targetDependencies[xCodeTargetName]);
if (createUnitTestTarget)
Expand Down Expand Up @@ -783,7 +799,7 @@ private void PrepareSections(XCodeGenerationContext context, List<Project.Config
ProjectBuildConfigurationForTarget configurationForTarget = null;
if (targetConf.Output == Project.Configuration.OutputType.IosTestBundle)
configurationForTarget = new ProjectBuildConfigurationForUnitTestTarget(targetConf, target, options);
else if (!targetConf.IsFastBuild || targetConf.Output == Project.Configuration.OutputType.AppleApp)
else if (!targetConf.IsFastBuild || (targetConf.Output == Project.Configuration.OutputType.AppleApp && targetConf.XcodeUseNativeProjectForFastBuildApp))
configurationForTarget = new ProjectBuildConfigurationForNativeTarget(targetConf, (ProjectNativeTarget)target, options);
else
configurationForTarget = new ProjectBuildConfigurationForLegacyTarget(targetConf, (ProjectLegacyTarget)target, options);
Expand Down
15 changes: 15 additions & 0 deletions Sharpmake/Project.Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2713,6 +2713,21 @@ public Strings XcodeResolvedUnitTestSourceFilesBuildExclude
private set { _XcodeResolvedUnitTestSourceFilesBuildExclude = value; }
}

/// <summary>
/// This property is used to override default behavior for XCode executable projects
/// configuration compiled using fastbuild.
/// If true(default), it will use a native XCode project to execute fastbuild
/// If false, it will use a makefile project to execute fastbuild.
/// </summary>
/// <remarks>
/// When using the default value, the project will not contain source files. The reason is we can't have source files
/// in the project as otherwise xcode will compile them itself and it will then try to relink the executable with those.
/// This will create unresolved errors.
/// When a native project is used Xcode will handle signing, package creation. These steps must be implemented by yourself if you
/// decide to use a makefile project. However only a makefile project can have source files.
/// </remarks>
public bool XcodeUseNativeProjectForFastBuildApp { get; set; } = true;

public Strings ResolvedSourceFilesBlobExclude = new Strings();

public Strings ResolvedSourceFilesGenerateXmlDocumentationExclude = new Strings();
Expand Down

0 comments on commit e7ef130

Please sign in to comment.