-
Notifications
You must be signed in to change notification settings - Fork 4
Fix the builds on macOS (universal). #26
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef MACOS_H | ||
#define MACOS_H | ||
|
||
#include <vector> | ||
#include <string> | ||
#include <filesystem> | ||
|
||
namespace macos { | ||
|
||
// get the full argv passed to the main process | ||
std::vector<std::string> get_argv(); | ||
|
||
} | ||
|
||
#endif //MACOS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "util/macos.h" | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
std::vector<std::string> macos::get_argv() { | ||
std::vector<std::string> argv; | ||
NSArray *argv_objc = [[NSProcessInfo processInfo] arguments]; | ||
for (NSString *arg in argv_objc) { | ||
argv.push_back([arg UTF8String]); | ||
} | ||
return argv; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,32 @@ def add_platform_config(*args, **kwargs): | |
executable = 'python.exe', | ||
) | ||
|
||
add_platform_config( | ||
platform = 'macos', | ||
arch = 'x86_64', | ||
source_url = 'https://github.com/indygreg/python-build-standalone/releases/download/' | ||
'20231002/cpython-3.12.0+20231002-x86_64-apple-darwin-install_only.tar.gz', | ||
so_suffixes = ['.so', '.dylib'], | ||
ext_suffixes = ['.so'], | ||
so_path = 'lib/libpython3.12.dylib', | ||
python_lib_dir = 'lib/python3.12', | ||
python_ext_dir = 'lib/python3.12/lib-dynload', | ||
executable = 'bin/python3.12', | ||
) | ||
|
||
add_platform_config( | ||
platform = 'macos', | ||
arch = 'arm64', | ||
source_url = 'https://github.com/indygreg/python-build-standalone/releases/download/' | ||
'20231002/cpython-3.12.0+20231002-aarch64-apple-darwin-install_only.tar.gz', | ||
so_suffixes = ['.so', '.dylib'], | ||
ext_suffixes = ['.so'], | ||
so_path = 'lib/libpython3.12.dylib', | ||
python_lib_dir = 'lib/python3.12', | ||
python_ext_dir = 'lib/python3.12/lib-dynload', | ||
executable = 'bin/python3.12', | ||
) | ||
|
||
|
||
def fetch_python_for_platform(platform: str, arch: str, dest_dir: pathlib.Path): | ||
config = platform_configs[(platform, arch)] | ||
|
@@ -80,11 +106,21 @@ def prepare_for_platform(platform: str, arch: str, | |
shutil.unpack_archive(src_dir / pathlib.Path(config.source_url).name, extract_dir = src_dir) | ||
|
||
src = src_dir / 'python' | ||
src_lib_path = src / config.so_path | ||
lib_filename = pathlib.Path(config.so_path).name | ||
|
||
if platform == 'macos': | ||
# Rename the library id (which we depend on) to be in @rpath. | ||
# (it defaults to /install/lib/) | ||
subprocess.run(['install_name_tool', '-id', f'@rpath/{lib_filename}', src_lib_path], check=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should maybe be performed on the copy instead, but that doesn't work because the copy isn't what is being linked, rendering the id change useless, and the final binary links to |
||
|
||
dest_dir.mkdir(parents=True, exist_ok=True) | ||
shutil.copy2(src_lib_path, dest_dir) | ||
|
||
shutil.copy2(src / config.so_path, dest_dir) | ||
subprocess.run(['strip', '-s', str(dest_dir / pathlib.Path(config.so_path).name)], check=True) | ||
if platform == 'macos': | ||
subprocess.run(['strip', '-x', dest_dir / lib_filename], check=True) | ||
else: | ||
subprocess.run(['strip', '-s', dest_dir / lib_filename], check=True) | ||
|
||
if (src / config.python_ext_dir).exists(): | ||
dest_ext_dir = dest_dir / 'python3.12' / 'lib-dynload' | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.