Skip to content

rules_python and linking with libpython #3153

Answered by rickeylev
canada-geek asked this question in Q&A
Discussion options

You must be logged in to vote

By hardcoding, i'm guessing you mean adding -lpython3.12 (the version specific part)?

Two thoughts come to mind:

(1) Use a select(). You'll have to enumerate the condition -> values. If that set is small, then this is an easy and teneable option. e.g. linkopts = select({":is_py_312": ["-lpython3.12"], ...}), where is_py_312 is e.g. config_setting(<match @rules_python//python/config_settings:python_version_major_minor = 3.12>)

(2) Custom rule that reads the settings and populates CcInfo link opts. Something like this:

def _libpython_linkopts_impl(ctx):
  runtime = ctx.toolchains["string-from-below"].py3_runtime
  libname = "python{major}.{minor}{ft}".format(
      major = runtime.interpret…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by canada-geek
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants