diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 00000000..0df17dd0 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +6.2.1 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 40c8c4eb..08c5597c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ pyvenv.cfg *.pyc *~ dist/ +bazel-* diff --git a/BUILD.bazel b/BUILD.bazel index e69de29b..608070cc 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -0,0 +1,12 @@ +package(default_visibility = ["//visibility:public"]) + + +filegroup( + name = "libmagic_linux", + srcs = [ + "libmagic.so", + "libmagic.so.1", + "libmagic.so.1.0.0", + ], + visibility = ["//visibility:public"], +) diff --git a/WORKSPACE b/WORKSPACE index fd686eee..47acb25c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,7 +1,17 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +http_archive( + name = "rules_foreign_cc", + sha256 = "476303bd0f1b04cc311fc258f1708a5f6ef82d3091e53fd1977fa20383425a6a", + strip_prefix = "rules_foreign_cc-0.10.1", + url = "https://github.com/bazelbuild/rules_foreign_cc/releases/download/0.10.1/rules_foreign_cc-0.10.1.tar.gz", +) + +load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") + +rules_foreign_cc_dependencies() http_archive( - name = "libmagic", + name = "libmagic_macos", sha256 = "09c588dac9cff4baa054f51a36141793bcf64926edc909594111ceae60fce4ee", strip_prefix = "file-5.31", urls = [ @@ -11,7 +21,7 @@ http_archive( "./configure", "make", "make install", - "cp src/.libs/libmagic.dylib /usr/local/lib/libmagic.dylib", + "cp src/.libs/libmagic.dylib /usr/local/lib/libmagic.dylib || true", ], build_file_content = """ cc_library( @@ -21,4 +31,4 @@ cc_library( linkstatic = 1, visibility = ['//visibility:public'], )""", -) \ No newline at end of file +) diff --git a/libmagic.so b/libmagic.so new file mode 120000 index 00000000..26e2f2ce --- /dev/null +++ b/libmagic.so @@ -0,0 +1 @@ +libmagic.so.1.0.0 \ No newline at end of file diff --git a/libmagic.so.1 b/libmagic.so.1 new file mode 120000 index 00000000..26e2f2ce --- /dev/null +++ b/libmagic.so.1 @@ -0,0 +1 @@ +libmagic.so.1.0.0 \ No newline at end of file diff --git a/libmagic.so.1.0.0 b/libmagic.so.1.0.0 new file mode 100755 index 00000000..639a592d Binary files /dev/null and b/libmagic.so.1.0.0 differ diff --git a/magic/BUILD.bazel b/magic/BUILD.bazel index 5e956a7d..8f6fa019 100644 --- a/magic/BUILD.bazel +++ b/magic/BUILD.bazel @@ -2,9 +2,10 @@ py_library( name = "loader", srcs = ["loader.py", "__init__.py"], imports = [".."], - data = [ - "@libmagic//:libmagic", - ], + data = select({ + "@platforms//os:linux": ["//:libmagic_linux"], + "@platforms//os:osx": [], # does not support macos for hermetic(?) build + }), visibility = ["//visibility:public"], ) @@ -16,4 +17,4 @@ py_library( ":loader", ], visibility = ["//visibility:public"], -) \ No newline at end of file +) diff --git a/setup.py b/setup.py index 06386c30..9ee0e8ff 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def read(file_name): long_description_content_type='text/markdown', packages=['magic'], package_data={ - 'magic': ['py.typed', '*.pyi', '**/*.pyi'], + 'magic': ['py.typed', '*.pyi', '**/*.pyi', '**/BUILD.bazel', 'WORKSPACE', 'libmagic.so*'], }, keywords="mime magic file", license="MIT", diff --git a/test/BUILD.bazel b/test/BUILD.bazel index fe19b5cd..ae93977d 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -5,8 +5,8 @@ py_test( "//magic:compat", ], data = [ - "testdata" - ] + "testdata", + ], ) py_test( @@ -16,6 +16,6 @@ py_test( "//magic:compat", ], data = [ - "testdata" + "testdata", ] -) \ No newline at end of file +)