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

feat: add watch-widget type target #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion packages/apple-targets/src/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type ExtensionType =
| "imessage"
| "clip"
| "watch"
| "watch-widget"
| "location-push"
| "credentials-provider"
| "account-auth"
Expand Down Expand Up @@ -264,6 +265,7 @@ export function productTypeForType(type: ExtensionType) {
export function needsEmbeddedSwift(type: ExtensionType) {
return [
"watch",
"watch-widget",
"spotlight",
"share",
"intent",
Expand All @@ -276,7 +278,7 @@ export function needsEmbeddedSwift(type: ExtensionType) {
}

export function getFrameworksForType(type: ExtensionType) {
if (type === "widget") {
if (type === "widget" || type === "watch-widget") {
return [
// CD07060B2A2EBE2E009C1192 /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; };
"WidgetKit",
Expand Down
87 changes: 85 additions & 2 deletions packages/apple-targets/src/withXcodeChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
productTypeForType,
} from "./target";
import fixture from "./template/XCBuildConfiguration.json";
import { withXcodeProjectBeta } from "./withXcparse";
const TemplateBuildSettings = fixture as unknown as Record<
string,
{
Expand All @@ -37,7 +38,6 @@ const TemplateBuildSettings = fixture as unknown as Record<
info: any;
}
>;
import { withXcodeProjectBeta } from "./withXcparse";

export type XcodeSettings = {
name: string;
Expand Down Expand Up @@ -447,6 +447,87 @@ function createWatchAppConfigurationList(

return configurationList;
}
function createWatchWidgetConfigurationList(
project: XcodeProject,
{
name,
cwd,
bundleId,
deploymentTarget,
currentProjectVersion,
hasAccentColor,
}: XcodeSettings
) {
const mainAppTarget = getMainAppTarget(project).getDefaultConfiguration();
// NOTE: No base Info.plist needed.

const common: BuildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME: "AppIcon",
CLANG_ANALYZER_NONNULL: "YES",
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION: "YES_AGGRESSIVE",
CLANG_CXX_LANGUAGE_STANDARD: "gnu++20",

CLANG_ENABLE_OBJC_WEAK: "YES",
CLANG_WARN_DOCUMENTATION_COMMENTS: "YES",
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER: "YES",
CLANG_WARN_UNGUARDED_AVAILABILITY: "YES_AGGRESSIVE",
CODE_SIGN_STYLE: "Automatic",
CURRENT_PROJECT_VERSION: currentProjectVersion,
GCC_C_LANGUAGE_STANDARD: "gnu11",
INFOPLIST_FILE: cwd + "/Info.plist",
GENERATE_INFOPLIST_FILE: "YES",
INFOPLIST_KEY_CFBundleDisplayName: name,
// @ts-expect-error Not part of xcode project types yet
INTENTS_CODEGEN_LANGUAGE: "Swift",
LD_RUNPATH_SEARCH_PATHS: "$(inherited) @executable_path/Frameworks",
MARKETING_VERSION: "1.0",
MTL_FAST_MATH: "YES",
PRODUCT_BUNDLE_IDENTIFIER: bundleId,
PRODUCT_NAME: "$(TARGET_NAME)",
SDKROOT: "watchos",
SKIP_INSTALL: "YES",
SWIFT_EMIT_LOC_STRINGS: "YES",
SWIFT_OPTIMIZATION_LEVEL: "-Onone",
SWIFT_VERSION: "5.0",
TARGETED_DEVICE_FAMILY: "4",
WATCHOS_DEPLOYMENT_TARGET: deploymentTarget ?? "9.4",
};

if (hasAccentColor) {
common.ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = "$accent";
}

const debugBuildConfig = XCBuildConfiguration.create(project, {
name: "Debug",
buildSettings: {
...common,
// Diff
MTL_ENABLE_DEBUG_INFO: "INCLUDE_SOURCE",
SWIFT_ACTIVE_COMPILATION_CONDITIONS: "DEBUG $(inherited)",
// SWIFT_ACTIVE_COMPILATION_CONDITIONS: "DEBUG",
DEBUG_INFORMATION_FORMAT: "dwarf", // NOTE
},
});

const releaseBuildConfig = XCBuildConfiguration.create(project, {
name: "Release",
buildSettings: {
...common,
// Diff
SWIFT_OPTIMIZATION_LEVEL: "-Owholemodule",
COPY_PHASE_STRIP: "NO",
DEBUG_INFORMATION_FORMAT: "dwarf-with-dsym",
},
});

const configurationList = XCConfigurationList.create(project, {
buildConfigurations: [debugBuildConfig, releaseBuildConfig],
defaultConfigurationIsVisible: 0,
defaultConfigurationName: "Release",
});

return configurationList;
}
function createSafariConfigurationList(
project: XcodeProject,
{
Expand Down Expand Up @@ -734,6 +815,8 @@ function createConfigurationListForType(
return createAppClipConfigurationList(project, props);
} else if (props.type === "watch") {
return createWatchAppConfigurationList(project, props);
} else if (props.type === "watch-widget") {
return createWatchWidgetConfigurationList(project, props);
} else {
// TODO: More
return createNotificationContentConfigurationList(project, props);
Expand Down Expand Up @@ -1017,7 +1100,7 @@ async function applyXcodeChanges(
})
);

let assetFiles = [
const assetFiles = [
// All assets`
// "assets/*",
// NOTE: Single-level only
Expand Down