Bug 239990 - devel/llvm90 and devel/llvm80: Add option to install python bindings to libclang
Summary: devel/llvm90 and devel/llvm80: Add option to install python bindings to libclang
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Brooks Davis
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-20 14:07 UTC by chardon.frederic
Modified: 2019-09-06 11:07 UTC (History)
1 user (show)

See Also:
bugzilla: maintainer-feedback? (brooks)


Attachments
python bindings (3.80 KB, patch)
2019-08-20 14:07 UTC, chardon.frederic
no flags Details | Diff
python bindings v2 (2.55 KB, patch)
2019-08-21 19:30 UTC, chardon.frederic
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description chardon.frederic 2019-08-20 14:07:01 UTC
Created attachment 206728 [details]
python bindings

Attached patch add an option to install the python bindings to libclang for devel/llvm80 and devel/llvm90.
Comment 1 Brooks Davis freebsd_committer 2019-08-20 19:18:07 UTC
I'll look at incorporating this as I find time.  The current version won't survive "make build-plist" so isn't committable as is.
Comment 2 chardon.frederic 2019-08-21 04:29:33 UTC
(In reply to Brooks Davis from comment #1)
Mmm sorry, I didn't think about that.

Actually, with just the Makefile patch:
diff --git a/devel/llvm90/Makefile b/devel/llvm90/Makefile
index 49eb9322f6ca..4ffd28aa8245 100644
--- a/devel/llvm90/Makefile
+++ b/devel/llvm90/Makefile
@@ -66,10 +66,10 @@ CMAKE_ARGS+=        -DPYTHON_EXECUTABLE=${PYTHON_CMD} \
 CFLAGS+=       -DNDEBUG
 CXXFLAGS+=     -DNDEBUG
 
-OPTIONS_DEFINE=        BE_AMDGPU CLANG DOCS EXTRAS LIT LLD LLDB
+OPTIONS_DEFINE=        BE_AMDGPU CLANG DOCS EXTRAS LIT LLD LLDB PYCLANG
 OPTIONS_DEFINE_amd64=  COMPILER_RT GOLD OPENMP
 OPTIONS_DEFINE_i386=   COMPILER_RT OPENMP
-OPTIONS_DEFAULT=       BE_AMDGPU BE_STANDARD CLANG EXTRAS LIT LLD LLDB
+OPTIONS_DEFAULT=       BE_AMDGPU BE_STANDARD CLANG EXTRAS LIT LLD LLDB PYCLANG
 OPTIONS_DEFAULT_amd64= COMPILER_RT GOLD OPENMP
 OPTIONS_DEFAULT_i386=  COMPILER_RT OPENMP
 OPTIONS_SINGLE=                BACKENDS
@@ -125,6 +125,10 @@ LLDB_PORTDOCS=             lldb
 LLDB_VARS=             _USES_PYTHON=python:3.6+
 OPENMP_DESC=           Install libomp, the LLVM OpenMP runtime library
 OPENMP_DISTFILES=      openmp-${DISTVERSION}.src${EXTRACT_SUFX}
+PYCLANG_DESC=  Install python bindings to libclang
+PYCLANG_IMPLIES=       CLANG
+PYCLANG_VARS=  _USES_PYTHON=python:3.6+
+PYCLANG_CMAKE_ON= -DCLANG_PYTHON_BINDINGS_VERSIONS=${PYTHON_VER}
 
 .if defined(WITH_DEBUG)
 CMAKE_BUILD_TYPE=      RelWithDebInfo


"make build-plist" dtrt: here is the diff to pkg-plist after running build-plist:

diff --git a/devel/llvm90/pkg-plist b/devel/llvm90/pkg-plist
index 8e42470d8d67..a8a5cef6d6ed 100644
--- a/devel/llvm90/pkg-plist
+++ b/devel/llvm90/pkg-plist
@@ -92,6 +92,9 @@ bin/sancov%%LLVM_SUFFIX%%
 %%LIT%%llvm%%LLVM_SUFFIX%%/bin/lit
 %%LIT%%bin/llvm-lit%%LLVM_SUFFIX%%
 %%LIT%%llvm%%LLVM_SUFFIX%%/bin/llvm-lit
+%%CLANG%%llvm%%LLVM_SUFFIX%%/%%PYTHON_SITELIBDIR%%/clang/__init__.py
+%%CLANG%%llvm%%LLVM_SUFFIX%%/%%PYTHON_SITELIBDIR%%/clang/cindex.py
+%%CLANG%%llvm%%LLVM_SUFFIX%%/%%PYTHON_SITELIBDIR%%/clang/enumerations.py
 %%LLDB%%llvm%%LLVM_SUFFIX%%/%%PYTHON_SITELIBDIR%%/lldb/__init__.py
 %%LLDB%%llvm%%LLVM_SUFFIX%%/%%PYTHON_SITELIBDIR%%/lldb/_lldb.so
 %%LLDB%%llvm%%LLVM_SUFFIX%%/%%PYTHON_SITELIBDIR%%/lldb/embedded_interpreter.py


I tested it only on llvm90, but since the build-plist is (almost) identical to all llvm 70 to 90 I believe  it should work the same.
Comment 3 Brooks Davis freebsd_committer 2019-08-21 09:02:08 UTC
That isn't quite right because then non-PYCLANG installs will fail.  You need to alter build-plist to not add %%CLANG%% and add %%PYCLANG%% like your manual change did.  That process isn't exactly clean, but I'd probably do something like exclude \.py$ from the the %%CLANG%% case and add a clang/.*\.py$ case for %%PYCLANG%%.
Comment 4 chardon.frederic 2019-08-21 19:30:18 UTC
Created attachment 206761 [details]
python bindings v2
Comment 5 chardon.frederic 2019-08-21 19:30:52 UTC
Now I think I got it right :)
Comment 6 commit-hook freebsd_committer 2019-08-23 10:07:03 UTC
A commit references this bug:

Author: brooks
Date: Fri Aug 23 10:06:01 UTC 2019
New revision: 509638
URL: https://svnweb.freebsd.org/changeset/ports/509638

Log:
  New option PYCLANG to add python binding for clang.

  PR:		239990
  Submitted by:	chardon.frederic@gmail.com

Changes:
  head/devel/llvm90/Makefile
  head/devel/llvm90/pkg-plist
Comment 7 Kubilay Kocak freebsd_committer freebsd_triage 2019-09-06 05:19:49 UTC
@Brooks Is this now resolved/FIXED?
Comment 8 Brooks Davis freebsd_committer 2019-09-06 10:33:14 UTC
(In reply to Kubilay Kocak from comment #7)
I haven't done llvm80.  I've queued up enough changes there that I'll do a rolled up commit of them soon.
Comment 9 Kubilay Kocak freebsd_committer freebsd_triage 2019-09-06 10:38:41 UTC
(In reply to Brooks Davis from comment #8)

Ah thank you, I missed that it had only been done for llvm90
Comment 10 commit-hook freebsd_committer 2019-09-06 11:05:03 UTC
A commit references this bug:

Author: brooks
Date: Fri Sep  6 11:04:45 UTC 2019
New revision: 511300
URL: https://svnweb.freebsd.org/changeset/ports/511300

Log:
  Assorted build improvements:

   - Add a build conflict for commonmark-cmark-* when DOCS are enabled.
     This prevents a failure later on in the build. [0]

   - Add a new option BE_AMDGPU which can be used to enable the AMDGPU
     backed used by mesa when BE_NATIVE or BE_FREEBSD is set.  Enable this
     option by default to limit later surprises. [1]

   - New option PYCLANG to add python binding for clang. [2]

  PR:		239636 [0], 230789 [1], 239990 [2]
  Submitted by:	chardon.frederic@gmail.com [2]
  Sponsored by:	DARPA, AFRL

Changes:
  head/devel/llvm80/Makefile
  head/devel/llvm80/pkg-plist
Comment 11 Brooks Davis freebsd_committer 2019-09-06 11:07:02 UTC
Applied to llvm80.