Skip to content

Commit

Permalink
Bump the libffi version to newest, and update rules to build on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshVarga committed Jan 14, 2025
1 parent f504bdf commit 1efdd71
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 21 deletions.
117 changes: 99 additions & 18 deletions dependency_support/org_sourceware_libffi/bundled.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ automake_substitution(
substitutions = AUTOMAKE_SUBSTITUTIONS,
)

AUTOMAKE_SUBSTITUTIONS_AARCH64 = {
"TARGET": "AARCH64",
"HAVE_LONG_DOUBLE": "0",
"FFI_EXEC_TRAMPOLINE_TABLE": "1",
}

automake_substitution(
name = "ffi_h_aarch64",
src = "include/ffi.h.in",
out = "generated/include_aarch64/ffi.h",
substitutions = AUTOMAKE_SUBSTITUTIONS_AARCH64,
)

genrule(
name = "fficonfig_h",
srcs = ["fficonfig.h.in"],
Expand All @@ -53,45 +66,111 @@ DEFINES = [
"STDC_HEADERS=1",
]

ARM64_MAC_DEFINES = [
"HAVE_ALLOCA_H=1",
"HAVE_AS_CFI_PSEUDO_OP=1",
"HAVE_HIDDEN_VISIBILITY_ATTRIBUTE=1",
"HAVE_STDIO_H=1",
"HAVE_STDLIB_H=1",
"HAVE_STRING_H=1",
"HAVE_INTTYPES_H=1",
"HAVE_STDINT_H=1",
"HAVE_STRINGS_H=1",
"HAVE_SYS_STAT_H=1",
"HAVE_SYS_TYPES_H=1",
"HAVE_UNISTD_H=1",
"STDC_HEADERS=1",
"HAVE_DLFCN_H=1",
"SIZEOF_SIZE_T=8",
"HAVE_MEMCPY=1",
"SIZEOF_DOUBLE=8",
"SIZEOF_LONG_DOUBLE=8",
"SYMBOL_UNDERSCORE=1",
"FFI_EXEC_TRAMPOLINE_TABLE=1",
"HAVE_RO_EH_FRAME=1",
"EH_FRAME_FLAGS=\"a\"",
]

copy(
name = "ffitarget_h",
src = "src/x86/ffitarget.h",
out = "generated/include/ffitarget.h",
)

copy(
name = "ffitarget_h_aarch64",
src = "src/aarch64/ffitarget.h",
out = "generated/include_aarch64/ffitarget.h",
)

cc_library(
name = "libffi",
srcs = [
"generated/fficonfig.h",
"generated/include/ffi.h",
"generated/include/ffitarget.h",
"include/ffi_cfi.h",
"include/ffi_common.h",
"include/tramp.h",
"src/closures.c",
"src/debug.c",
"src/java_raw_api.c",
"src/prep_cif.c",
"src/raw_api.c",
"src/types.c",
"src/x86/asmnames.h",
"src/x86/ffi.c",
"src/x86/ffi64.c",
"src/x86/ffiw64.c",
"src/x86/internal.h",
"src/x86/internal64.h",
"src/x86/sysv.S",
"src/x86/unix64.S",
"src/x86/win64.S",
],
"src/tramp.c",
] + select({
"@bazel_tools//src/conditions:darwin_arm64": [
":ffi_h_aarch64",
":ffitarget_h_aarch64",
"src/aarch64/sysv.S",
"src/aarch64/ffi.c",
"src/aarch64/internal.h",
],
"@bazel_tools//src/conditions:darwin_x86_64": [
":ffi_h",
":ffitarget_h",
"src/x86/unix64.S",
"src/x86/ffi64.c",
"src/x86/ffiw64.c",
"src/x86/win64.S",
"src/x86/internal64.h",
"src/x86/asmnames.h",
],
"@bazel_tools//src/conditions:linux": [
":ffi_h",
":ffitarget_h",
"src/x86/sysv.S",
"src/x86/ffi.c",
"src/x86/internal.h",
"src/x86/unix64.S",
"src/x86/ffi64.c",
"src/x86/ffiw64.c",
"src/x86/win64.S",
"src/x86/internal64.h",
"src/x86/asmnames.h",
],
}),
copts = [
"-Wno-deprecated-declarations",
],
includes = [
"generated",
"generated/include",
"include",
],
defines = DEFINES,
] + select({
"@bazel_tools//src/conditions:darwin_arm64": [
"generated/include_aarch64",
],
"@bazel_tools//src/conditions:darwin_x86_64": [
"generated/include",
],
"@bazel_tools//src/conditions:linux": [
"generated/include",
],
}),
defines = select({
"@bazel_tools//src/conditions:darwin_arm64": ARM64_MAC_DEFINES,
"@bazel_tools//src/conditions:darwin_x86_64": DEFINES,
"@bazel_tools//src/conditions:linux": DEFINES,
}),
textual_hdrs = ["src/dlmalloc.c"],
visibility = ["//visibility:public"],
)
Expand Down Expand Up @@ -123,7 +202,7 @@ cc_library(
"offsets",
"pr1172638",
"promotion",
"pyobjc-tc",
"pyobjc_tc",
"return_dbl",
"return_dbl1",
"return_dbl2",
Expand Down Expand Up @@ -188,10 +267,14 @@ cc_library(
srcs = [
"testsuite/libffi.closures/ffitest.h",
"testsuite/libffi.closures/%s.c" % closures_test,
"testsuite/libffi.call/ffitest.h",
],
deps = [
":libffi",
],
includes = [
".",
],
) for closures_test in [
"closure_fn0",
"closure_fn1",
Expand Down Expand Up @@ -260,13 +343,11 @@ cc_library(
"cls_sshort",
"cls_struct_va1",
"cls_uchar",
"cls_uchar_va",
"cls_uint",
"cls_uint_va",
"cls_ulong_va",
"cls_ulonglong",
"cls_ushort",
"cls_ushort_va",
"err_bad_abi",
"huge_struct",
"nested_struct",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def org_sourceware_libffi():
http_archive,
name = "org_sourceware_libffi",
urls = [
"https://github.com/libffi/libffi/releases/download/v3.3/libffi-3.3.tar.gz",
"https://github.com/libffi/libffi/releases/download/v3.4.6/libffi-3.4.6.tar.gz",
],
strip_prefix = "libffi-3.3",
sha256 = "72fba7922703ddfa7a028d513ac15a85c8d54c8d67f55fa5a4802885dc652056",
strip_prefix = "libffi-3.4.6",
sha256 = "b0dea9df23c863a7a50e825440f3ebffabd65df1497108e5d437747843895a4e",
build_file = Label("@rules_hdl//dependency_support:org_sourceware_libffi/bundled.BUILD.bazel"),
)

0 comments on commit 1efdd71

Please sign in to comment.