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

Fix unknown argument: '-export-dynamic' on macOS #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 8 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ def read_version():

gethostname = setuptools.Extension(
"gethostname",
sources=["src/sagemaker_training/c/gethostname.c", "src/sagemaker_training/c/jsmn.c"],
sources=[
"src/sagemaker_training/c/gethostname.c",
"src/sagemaker_training/c/jsmn.c",
],
include_dirs=["src/sagemaker_training/c"],
extra_compile_args=["-Wall", "-shared", "-export-dynamic", "-ldl"],
extra_compile_args=["-Wall", "-shared", "-Wl,-export-dynamic", "-ldl"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: separate out -Wl and -export-dynamic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: explore separating out linker and compile args if any, guideline- https://setuptools.pypa.io/en/latest/userguide/ext_modules.html#compiler-and-linker-options

Copy link
Author

@jponf jponf Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand your suggestion. The -Wl option is a comma separated list of options to forward to the linker. In the link you suggested there is an example where -Wl is joint with the option "-rpath"

then, a linker-specific option like -Wl,-rpath for each element of Extension.runtime_library_dirs,

I did some more tests, gcc accepts the stand-alone -export-dynamic but clang does not, it requires it being passed with "-Wl" to properly forward it to the linker. Additionally, separating "-Wl" and "-export-dynamic" breaks in both gcc and clang since "-Wl" alone is an unrecognized option. Finally, I've tested moving the option to runtime_library_dirs and extra_link_args and only works on the first.

If you want I could move the option to the argument runtime_library_dirs but the value would still be "-Wl,-export-dynamic". The only difference it would make is the order in which the option will be appended into the command to invoke gcc or clang. I'm ok with either change.

)

setuptools.setup(
Expand All @@ -63,7 +66,9 @@ def read_version():
description="Open source library for creating containers to run on Amazon SageMaker.",
packages=packages,
package_dir={"sagemaker_training": "src/sagemaker_training"},
py_modules=[os.path.splitext(os.path.basename(path))[0] for path in glob("src/*.py")],
py_modules=[
os.path.splitext(os.path.basename(path))[0] for path in glob("src/*.py")
],
ext_modules=[gethostname],
long_description=read("README.md"),
long_description_content_type="text/markdown",
Expand Down