Skip to content

[LLVM][CMake] Add ffi_static target for the FFI static library #78779

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

Merged
merged 2 commits into from
Jan 22, 2024

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Jan 19, 2024

Summary:
This patch is an attempt to make the find_package(FFI) support in LLVM
prefer to provide the static library version if present. This is currently
an optional library for building libffi, and its presence implies that
it should likely be used. This patch is an attempt to fix some problems
observed with testing programs linked against libffi on many different
systems that could have conflicting paths. Linking it statically
prevents this.

This patch adds the ffi_static target for this library.

Summary:
This patch is an attempt to make the `find_package(FFI)` support in LLVM
prefer to use the static library version if present. This is currently
an optional library for building `libffi`, and its presence implies that
it should likely be used. This patch is an attempt to fix some problems
observed with testing programs linked against `libffi` on many different
systems that could have conflicting paths. Linking it statically
prevents this.

If this is not a desirable solution, we could either roll this logic
custom, or handling it via a `COMPONENT` or something.
@llvmbot llvmbot added the cmake Build system in general and CMake in particular label Jan 19, 2024
Copy link
Contributor

@doru1004 doru1004 left a comment

Choose a reason for hiding this comment

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

LGTM

@petrhosek
Copy link
Member

With other dependencies, we use dedicated flags, see for example:

set(LLVM_USE_STATIC_ZSTD FALSE CACHE BOOL "Use static version of zstd. Can be TRUE, FALSE")

Inside the FindFFI module, we would ideally expose the static library as a separate target, see for example:

find_library(zstd_STATIC_LIBRARY NAMES
zstd_static
"${CMAKE_STATIC_LIBRARY_PREFIX}zstd${CMAKE_STATIC_LIBRARY_SUFFIX}")

@MaskRay
Copy link
Member

MaskRay commented Jan 20, 2024

+1 for a new CMake variable. Many distributions prefer dynamic linking. Linking in libffi.a could cause a conflict (usually benign) if a program links against both libLLVM.so and libffi.so.

For libLLVM*.a users, it's possible that libffi.a works better.

@llvmbot llvmbot added the openmp:libomptarget OpenMP offload runtime label Jan 20, 2024
@jhuber6
Copy link
Contributor Author

jhuber6 commented Jan 20, 2024

With other dependencies, we use dedicated flags, see for example:

set(LLVM_USE_STATIC_ZSTD FALSE CACHE BOOL "Use static version of zstd. Can be TRUE, FALSE")

Inside the FindFFI module, we would ideally expose the static library as a separate target, see for example:

find_library(zstd_STATIC_LIBRARY NAMES
zstd_static
"${CMAKE_STATIC_LIBRARY_PREFIX}zstd${CMAKE_STATIC_LIBRARY_SUFFIX}")

Thanks for the pointer, made the change and some example usage.

Copy link
Contributor

@ronlieb ronlieb left a comment

Choose a reason for hiding this comment

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

applied locally and tested , LGTM

searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Jan 20, 2024
Premerge land patch from Joseph

Change-Id: I7dd70621ad9d2f96a07cbdc65ff0f6226c2a41fb
@jhuber6 jhuber6 changed the title [LLVM][CMake] Prefer to find libffi.a if present [LLVM][CMake] Add ffi_static target for the FFI static library Jan 20, 2024
@MaskRay
Copy link
Member

MaskRay commented Jan 20, 2024

I am not familiar with CMake, but should there be a LLVM_USE_STATIC_FFI to select libffi.a when both libffi.so and libffi.a are present?

@jhuber6
Copy link
Contributor Author

jhuber6 commented Jan 20, 2024

I am not familiar with CMake, but should there be a LLVM_USE_STATIC_FFI to select libffi.a when both libffi.so and libffi.a are present?

The user can decide which one to use based off of whether or not FFI_STATIC_LIBRARIES was set, as in the changed code in libomptarget.

@jhuber6 jhuber6 merged commit b689b4f into llvm:main Jan 22, 2024
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Apr 15, 2024
…78779)

Summary:
This patch is an attempt to make the `find_package(FFI)` support in LLVM
prefer to provide the static library version if present. This is
currently
an optional library for building `libffi`, and its presence implies that
it should likely be used. This patch is an attempt to fix some problems
observed with testing programs linked against `libffi` on many different
systems that could have conflicting paths. Linking it statically
prevents this.

This patch adds the `ffi_static` target for this library.

Change-Id: Ic3748bd220a942dff47467bc199532e37bf92d95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular openmp:libomptarget OpenMP offload runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants