@@ -419,62 +419,19 @@ function(add_mlir_python_extension libname extname)
419
419
message (FATAL_ERROR " Missing SOURCES argument to add_mlir_python_extension(${libname} , ..." )
420
420
endif ()
421
421
422
- # Build-time RPath layouts require to be a directory one up from the
423
- # binary root.
424
- # TODO: Don't reference the LLVM_BINARY_DIR here: the invariant is that
425
- # the output directory must be at the same level of the lib directory
426
- # where libMLIR.so is installed. This is presently not optimal from a
427
- # project separation perspective and a discussion on how to better
428
- # segment MLIR libraries needs to happen.
429
- # TODO: Remove this when downstreams are moved off of it.
430
- if (NOT ARG_OUTPUT_DIRECTORY )
431
- set (ARG_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR} /python )
432
- endif ()
433
-
434
- # Normally on unix-like platforms, extensions are built as "MODULE" libraries
435
- # and do not explicitly link to the python shared object. This allows for
436
- # some greater deployment flexibility since the extension will bind to
437
- # symbols in the python interpreter on load. However, it also keeps the
438
- # linker from erroring on undefined symbols, leaving this to (usually obtuse)
439
- # runtime errors. Building in "SHARED" mode with an explicit link to the
440
- # python libraries allows us to build with the expectation of no undefined
441
- # symbols, which is better for development. Note that not all python
442
- # configurations provide build-time libraries to link against, in which
443
- # case, we fall back to MODULE linking.
444
- if (Python3_LIBRARIES STREQUAL "" OR NOT MLIR_BINDINGS_PYTHON_LOCK_VERSION )
445
- set (PYEXT_LINK_MODE MODULE )
446
- set (PYEXT_LIBADD )
447
- else ()
448
- set (PYEXT_LINK_MODE SHARED )
449
- set (PYEXT_LIBADD ${Python3_LIBRARIES} )
450
- endif ()
451
-
452
422
# The actual extension library produces a shared-object or DLL and has
453
423
# sources that must be compiled in accordance with pybind11 needs (RTTI and
454
424
# exceptions).
455
- add_library (${libname}
456
- ${PYEXT_LINK_MODE}
425
+ pybind11_add_module (${libname}
457
426
${ARG_SOURCES}
458
427
)
459
428
460
- target_include_directories (${libname} PRIVATE
461
- "${Python3_INCLUDE_DIRS} "
462
- "${pybind11_INCLUDE_DIR} "
463
- )
464
-
465
- target_link_directories (${libname} PRIVATE
466
- "${Python3_LIBRARY_DIRS} "
467
- )
468
-
469
429
# The extension itself must be compiled with RTTI and exceptions enabled.
470
430
# Also, some warning classes triggered by pybind11 are disabled.
471
431
target_compile_options (${libname} PRIVATE
472
432
$< $< OR:$< CXX_COMPILER_ID:Clang> ,$< CXX_COMPILER_ID:AppleClang> ,$< CXX_COMPILER_ID:GNU> > :
473
433
# Enable RTTI and exceptions.
474
434
-frtti -fexceptions
475
- # Noisy pybind warnings
476
- -Wno-unused-value
477
- -Wno-covered-switch-default
478
435
>
479
436
$< $< CXX_COMPILER_ID:MSVC> :
480
437
# Enable RTTI and exceptions.
@@ -486,8 +443,6 @@ function(add_mlir_python_extension libname extname)
486
443
${libname} PROPERTIES
487
444
LIBRARY_OUTPUT_DIRECTORY ${ARG_OUTPUT_DIRECTORY}
488
445
OUTPUT_NAME "${extname} "
489
- PREFIX "${PYTHON_MODULE_PREFIX} "
490
- SUFFIX "${PYTHON_MODULE_SUFFIX}${PYTHON_MODULE_EXTENSION} "
491
446
NO_SONAME ON
492
447
)
493
448
@@ -501,13 +456,6 @@ function(add_mlir_python_extension libname extname)
501
456
)
502
457
endif ()
503
458
504
- # pybind11 requires binding code to be compiled with -fvisibility=hidden
505
- # For static linkage, better code can be generated if the entire project
506
- # compiles that way, but that is not enforced here. Instead, include a linker
507
- # script that explicitly hides anything but the PyInit_* symbols, allowing gc
508
- # to take place.
509
- set_target_properties (${libname} PROPERTIES CXX_VISIBILITY_PRESET "hidden" )
510
-
511
459
# Python extensions depends *only* on the public API and LLVMSupport unless
512
460
# if further dependencies are added explicitly.
513
461
target_link_libraries (${libname}
0 commit comments