-
Notifications
You must be signed in to change notification settings - Fork 14
issue/176: 支持macos编译 #178
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
Closed
Closed
issue/176: 支持macos编译 #178
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,61 @@ | ||
import os | ||
import platform | ||
|
||
|
||
def set_env(): | ||
if os.environ.get("INFINI_ROOT") == None: | ||
os.environ["INFINI_ROOT"] = os.path.expanduser("~/.infini") | ||
|
||
if platform.system() == "Windows": | ||
new_path = os.path.expanduser(os.environ.get("INFINI_ROOT") + "/bin") | ||
if new_path not in os.environ.get("PATH", ""): | ||
os.environ["PATH"] = f"{new_path};{os.environ.get('PATH', '')}" | ||
|
||
elif platform.system() == "Linux": | ||
new_path = os.path.expanduser(os.environ.get("INFINI_ROOT") + "/bin") | ||
if new_path not in os.environ.get("PATH", ""): | ||
os.environ["PATH"] = f"{new_path}:{os.environ.get('PATH', '')}" | ||
|
||
new_lib_path = os.path.expanduser(os.environ.get("INFINI_ROOT") + "/lib") | ||
if new_lib_path not in os.environ.get("LD_LIBRARY_PATH", ""): | ||
os.environ["LD_LIBRARY_PATH"] = ( | ||
f"{new_lib_path}:{os.environ.get('LD_LIBRARY_PATH', '')}" | ||
) | ||
""" | ||
Sets up environment variables for Infini software, supporting Windows, Linux, and macOS. | ||
""" | ||
|
||
infini_root_env = "INFINI_ROOT" | ||
if os.environ.get(infini_root_env) is None: | ||
default_infini_root = os.path.expanduser("~/.infini") | ||
os.environ[infini_root_env] = default_infini_root | ||
print(f"[Info] '{infini_root_env}' was not set. Using default: {default_infini_root}") | ||
|
||
infini_root = os.environ.get(infini_root_env) | ||
if not infini_root: | ||
raise RuntimeError(f"Could not determine or set {infini_root_env}") | ||
|
||
bin_path = os.path.join(infini_root, "bin") | ||
lib_path = os.path.join(infini_root, "lib") | ||
|
||
# Update PATH environment variable | ||
path_env_var = "PATH" | ||
current_path = os.environ.get(path_env_var, "") | ||
path_list = [p for p in current_path.split(os.pathsep) if p] | ||
if bin_path not in path_list: | ||
new_path_value = f"{bin_path}{os.pathsep}{current_path}" | ||
os.environ[path_env_var] = new_path_value | ||
print(f"[Info] Added '{bin_path}' to {path_env_var}") | ||
|
||
# Handle platform-specific library path environment variables | ||
system = platform.system() | ||
|
||
# Linux platform | ||
if system == "Linux": | ||
lib_path_env_var = "LD_LIBRARY_PATH" | ||
current_lib_path = os.environ.get(lib_path_env_var, "") | ||
lib_path_list = [p for p in current_lib_path.split(os.pathsep) if p] | ||
if lib_path not in lib_path_list: | ||
new_lib_path_value = f"{lib_path}{os.pathsep}{current_lib_path}" | ||
os.environ[lib_path_env_var] = new_lib_path_value | ||
print(f"[Info] Added '{lib_path}' to {lib_path_env_var}") | ||
|
||
# macOS platform | ||
elif system == "Darwin": | ||
lib_path_env_var = "DYLD_LIBRARY_PATH" | ||
current_lib_path = os.environ.get(lib_path_env_var, "") | ||
lib_path_list = [p for p in current_lib_path.split(os.pathsep) if p] | ||
if lib_path not in lib_path_list: | ||
new_lib_path_value = f"{lib_path}{os.pathsep}{current_lib_path}" | ||
os.environ[lib_path_env_var] = new_lib_path_value | ||
print(f"[Info] Added '{lib_path}' to {lib_path_env_var}") | ||
|
||
# Windows platform | ||
elif system == "Windows": | ||
print(f"[Info] On Windows, ensure '{lib_path}' is accessible (e.g., via PATH).") | ||
|
||
# Unsupported platforms | ||
else: | ||
raise RuntimeError("Unsupported platform.") | ||
raise RuntimeError(f"Unsupported platform: {system}. Cannot set library path.") | ||
|
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请按照之前的格式写,不同平台不要串在一起