Skip to content

Commit 8f72976

Browse files
committed
Allow for using a non-framework Python library.
1 parent 86fb158 commit 8f72976

3 files changed

Lines changed: 95 additions & 1 deletion

File tree

cookiecutter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"universal_build": true,
1717
"host_arch": "arm64",
1818
"min_os_version": "11.0",
19+
"use_framework": true,
1920
"_extensions": [
2021
"briefcase.integrations.cookiecutter.PythonVersionExtension",
2122
"briefcase.integrations.cookiecutter.PListExtension"

{{ cookiecutter.format }}/{{ cookiecutter.class_name }}/main.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
#import <Foundation/Foundation.h>
66
#import <AppKit/AppKit.h>
77
#import <Cocoa/Cocoa.h>
8+
{%- if cookiecutter.use_framework %}
89
#import <Python/Python.h>
10+
{%- else %}
11+
#import <Python.h>
12+
{%- endif %}
913
#include <dlfcn.h>
1014
#include <libgen.h>
1115
#include <mach-o/dyld.h>
@@ -96,7 +100,11 @@ int main(int argc, char *argv[]) {
96100

97101
// Set the home for the Python interpreter
98102
python_tag = @"{{ cookiecutter.python_version|py_tag }}";
103+
{%- if cookiecutter.use_framework %}
99104
python_home = [NSString stringWithFormat:@"%@/Python.framework/Versions/%@", frameworksPath, python_tag, nil];
105+
{%- else %}
106+
python_home = [NSString stringWithFormat:@"%@/python/", resourcePath, nil];
107+
{%- endif %}
100108
debug_log(@"PythonHome: %@", python_home);
101109
wtmp_str = Py_DecodeLocale([python_home UTF8String], NULL);
102110
status = PyConfig_SetString(&config, &config.home, wtmp_str);

{{ cookiecutter.format }}/{{ cookiecutter.formal_name }}.xcodeproj/project.pbxproj

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
0D354FEF2551C249009178D1 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D354FEE2551C249009178D1 /* Cocoa.framework */; };
1515
0D7B44A82555E01500CBC44B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0D7B44A72555E01500CBC44B /* Foundation.framework */; };
1616
0D7B44DA2556C84100CBC44B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D354FD72551BFBD009178D1 /* main.m */; };
17+
{%- if cookiecutter.use_framework %}
1718
6060E7722AF0B40500C04AE0 /* Python.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6060E76F2AF0B14D00C04AE0 /* Python.xcframework */; };
1819
6060E7732AF0B40500C04AE0 /* Python.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6060E76F2AF0B14D00C04AE0 /* Python.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
20+
{%- else %}
21+
AA0000022AF0B40500C04AE0 /* libpython{{ cookiecutter.python_version|py_tag }}.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = AA0000012AF0B14D00C04AE0 /* libpython{{ cookiecutter.python_version|py_tag }}.dylib */; };
22+
{%- endif %}
1923
/* End PBXBuildFile section */
2024

2125
/* Begin PBXCopyFilesBuildPhase section */
@@ -29,6 +33,7 @@
2933
name = "Embed Foundation Extensions";
3034
runOnlyForDeploymentPostprocessing = 0;
3135
};
36+
{%- if cookiecutter.use_framework %}
3237
6060E7742AF0B40500C04AE0 /* Embed Frameworks */ = {
3338
isa = PBXCopyFilesBuildPhase;
3439
buildActionMask = 2147483647;
@@ -40,6 +45,7 @@
4045
name = "Embed Frameworks";
4146
runOnlyForDeploymentPostprocessing = 0;
4247
};
48+
{%- endif %}
4349
/* End PBXCopyFilesBuildPhase section */
4450

4551
/* Begin PBXFileReference section */
@@ -53,7 +59,11 @@
5359
0D354FE52551C1E1009178D1 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
5460
0D354FEE2551C249009178D1 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
5561
0D7B44A72555E01500CBC44B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
62+
{%- if cookiecutter.use_framework %}
5663
6060E76F2AF0B14D00C04AE0 /* Python.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = Python.xcframework; sourceTree = "<group>"; };
64+
{%- else %}
65+
AA0000012AF0B14D00C04AE0 /* libpython{{ cookiecutter.python_version|py_tag }}.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libpython{{ cookiecutter.python_version|py_tag }}.dylib; path = Python/lib/libpython{{ cookiecutter.python_version|py_tag }}.dylib; sourceTree = "<group>"; };
66+
{%- endif %}
5767
/* End PBXFileReference section */
5868

5969
/* Begin PBXFrameworksBuildPhase section */
@@ -64,7 +74,11 @@
6474
0D354FE62551C1E1009178D1 /* AppKit.framework in Frameworks */,
6575
0D354FEF2551C249009178D1 /* Cocoa.framework in Frameworks */,
6676
0D7B44A82555E01500CBC44B /* Foundation.framework in Frameworks */,
77+
{%- if cookiecutter.use_framework %}
6778
6060E7722AF0B40500C04AE0 /* Python.xcframework in Frameworks */,
79+
{%- else %}
80+
AA0000022AF0B40500C04AE0 /* libpython{{ cookiecutter.python_version|py_tag }}.dylib in Frameworks */,
81+
{%- endif %}
6882
);
6983
runOnlyForDeploymentPostprocessing = 0;
7084
};
@@ -115,7 +129,11 @@
115129
60A04BBB28AF5E1000DAA9E5 /* Support */ = {
116130
isa = PBXGroup;
117131
children = (
132+
{%- if cookiecutter.use_framework %}
118133
6060E76F2AF0B14D00C04AE0 /* Python.xcframework */,
134+
{%- else %}
135+
AA0000012AF0B14D00C04AE0 /* libpython{{ cookiecutter.python_version|py_tag }}.dylib */,
136+
{%- endif %}
119137
);
120138
path = Support;
121139
sourceTree = "<group>";
@@ -131,7 +149,11 @@
131149
0D354FC52551BFBA009178D1 /* Frameworks */,
132150
0D354FC62551BFBA009178D1 /* Resources */,
133151
0D7B44EB2556C8B800CBC44B /* Embed Foundation Extensions */,
152+
{%- if cookiecutter.use_framework %}
134153
6060E7742AF0B40500C04AE0 /* Embed Frameworks */,
154+
{%- else %}
155+
AA0000032AF0B40500C04AE0 /* Embed Python lib */,
156+
{%- endif %}
135157
60A04BC128AF640400DAA9E5 /* Sign Python Binary Modules */,
136158
);
137159
buildRules = (
@@ -150,7 +172,7 @@
150172
isa = PBXProject;
151173
attributes = {
152174
BuildIndependentTargetsInParallel = YES;
153-
LastUpgradeCheck = 1540;
175+
LastUpgradeCheck = 2660;
154176
ORGANIZATIONNAME = "{{ cookiecutter.author }}";
155177
TargetAttributes = {
156178
0D354FC72551BFBA009178D1 = {
@@ -190,6 +212,27 @@
190212
/* End PBXResourcesBuildPhase section */
191213

192214
/* Begin PBXShellScriptBuildPhase section */
215+
{%- if not cookiecutter.use_framework %}
216+
AA0000032AF0B40500C04AE0 /* Embed Python lib */ = {
217+
isa = PBXShellScriptBuildPhase;
218+
alwaysOutOfDate = 1;
219+
buildActionMask = 2147483647;
220+
files = (
221+
);
222+
inputFileListPaths = (
223+
);
224+
inputPaths = (
225+
);
226+
name = "Embed Python lib";
227+
outputFileListPaths = (
228+
);
229+
outputPaths = (
230+
);
231+
runOnlyForDeploymentPostprocessing = 0;
232+
shellPath = /bin/sh;
233+
shellScript = "set -e\nDEST=\"$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/python\"\necho \"Embedding Python lib into $DEST\"\nmkdir -p \"$DEST\"\n# Copy the entire lib/ tree, preserving symlinks. Exclude static archives\n# and pkgconfig metadata that are not needed at runtime.\nrsync -a --delete --copy-unsafe-links \\\n --exclude='*.a' \\\n --exclude='pkgconfig' \\\n \"$PROJECT_DIR/Support/Python/lib/\" \"$DEST/lib/\"\n";
234+
};
235+
{%- endif %}
193236
60A04BC128AF640400DAA9E5 /* Sign Python Binary Modules */ = {
194237
isa = PBXShellScriptBuildPhase;
195238
alwaysOutOfDate = 1;
@@ -286,6 +329,7 @@
286329
ONLY_ACTIVE_ARCH = YES;
287330
PRODUCT_NAME = "{{ cookiecutter.formal_name }}";
288331
SDKROOT = macosx;
332+
STRING_CATALOG_GENERATE_SYMBOLS = YES;
289333
};
290334
name = Debug;
291335
};
@@ -345,6 +389,7 @@
345389
MTL_FAST_MATH = YES;
346390
PRODUCT_NAME = "{{ cookiecutter.formal_name }}";
347391
SDKROOT = macosx;
392+
STRING_CATALOG_GENERATE_SYMBOLS = YES;
348393
};
349394
name = Release;
350395
};
@@ -363,17 +408,37 @@
363408
COMBINE_HIDPI_IMAGES = YES;
364409
DEAD_CODE_STRIPPING = YES;
365410
ENABLE_HARDENED_RUNTIME = YES;
411+
{%- if cookiecutter.use_framework %}
366412
FRAMEWORK_SEARCH_PATHS = (
367413
"$(inherited)",
368414
"\"$(PROJECT_DIR)/Support\"",
369415
);
416+
{%- else %}
417+
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
418+
{%- endif %}
370419
GCC_C_LANGUAGE_STANDARD = gnu99;
420+
{%- if cookiecutter.use_framework %}
371421
HEADER_SEARCH_PATHS = "\"$(BUILT_PRODUCTS_DIR)/Python.framework/Headers\"";
422+
{%- else %}
423+
HEADER_SEARCH_PATHS = "\"$(PROJECT_DIR)/Support/Python/include/python{{ cookiecutter.python_version|py_tag }}\"";
424+
{%- endif %}
372425
INFOPLIST_FILE = "{{ cookiecutter.class_name }}/Info.plist";
426+
{%- if cookiecutter.use_framework %}
373427
LD_RUNPATH_SEARCH_PATHS = (
374428
"$(inherited)",
375429
"@executable_path/../Frameworks",
376430
);
431+
{%- else %}
432+
LD_RUNPATH_SEARCH_PATHS = (
433+
"$(inherited)",
434+
"@executable_path/../Frameworks",
435+
"@executable_path/../Resources/python/lib",
436+
);
437+
LIBRARY_SEARCH_PATHS = (
438+
"$(inherited)",
439+
"\"$(PROJECT_DIR)/Support/Python/lib\"",
440+
);
441+
{%- endif %}
377442
MACOSX_DEPLOYMENT_TARGET = {{ cookiecutter.min_os_version }};
378443
PRODUCT_BUNDLE_IDENTIFIER = "{{ cookiecutter.bundle }}.{{ cookiecutter.app_name }}";
379444
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -396,17 +461,37 @@
396461
DEAD_CODE_STRIPPING = YES;
397462
ENABLE_HARDENED_RUNTIME = YES;
398463
ENABLE_TESTABILITY = YES;
464+
{%- if cookiecutter.use_framework %}
399465
FRAMEWORK_SEARCH_PATHS = (
400466
"$(inherited)",
401467
"\"$(PROJECT_DIR)/Support\"",
402468
);
469+
{%- else %}
470+
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
471+
{%- endif %}
403472
GCC_C_LANGUAGE_STANDARD = gnu99;
473+
{%- if cookiecutter.use_framework %}
404474
HEADER_SEARCH_PATHS = "\"$(BUILT_PRODUCTS_DIR)/Python.framework/Headers\"";
475+
{%- else %}
476+
HEADER_SEARCH_PATHS = "\"$(PROJECT_DIR)/Support/Python/include/python{{ cookiecutter.python_version|py_tag }}\"";
477+
{%- endif %}
405478
INFOPLIST_FILE = "{{ cookiecutter.class_name }}/Info.plist";
479+
{%- if cookiecutter.use_framework %}
406480
LD_RUNPATH_SEARCH_PATHS = (
407481
"$(inherited)",
408482
"@executable_path/../Frameworks",
409483
);
484+
{%- else %}
485+
LD_RUNPATH_SEARCH_PATHS = (
486+
"$(inherited)",
487+
"@executable_path/../Frameworks",
488+
"@executable_path/../Resources/python/lib",
489+
);
490+
LIBRARY_SEARCH_PATHS = (
491+
"$(inherited)",
492+
"\"$(PROJECT_DIR)/Support/Python/lib\"",
493+
);
494+
{%- endif %}
410495
MACOSX_DEPLOYMENT_TARGET = {{ cookiecutter.min_os_version }};
411496
PRODUCT_BUNDLE_IDENTIFIER = "{{ cookiecutter.bundle }}.{{ cookiecutter.app_name }}";
412497
};

0 commit comments

Comments
 (0)