build swig/pcre2 in bazel; tweak swig_java.bzl

This commit is contained in:
Laurent Perron
2022-12-31 11:55:09 +01:00
parent 2e213ea167
commit c1c0af9e51
8 changed files with 13766 additions and 285 deletions

View File

@@ -152,10 +152,79 @@ new_git_repository(
load("@pybind11_bazel//:python_configure.bzl", "python_configure")
python_configure(name = "local_config_python", python_version = "3")
# pcre source code repository
http_archive(
name = "pcre2",
build_file_content = """\
cc_library(
name = 'pcre',
srcs = glob(['pcre32*.c']),
hdrs = ["pcre_chartables.c"] + glob(['*.h', 'pcre_*.c']),
copts = [
"-DLINK_SIZE=4",
"-DNEWLINE",
"-DPOSIX_MALLOC_THRESHOLD=10",
"-DPARENS_NEST_LIMIT=250",
"-DMATCH_LIMIT=10000000",
"-DMATCH_LIMIT_RECURSION=10000000",
"-DMAX_NAME_SIZE=32",
"-DMAX_NAME_COUNT=10000",
],
includes = ['.'],
visibility = ['//visibility:public'],
)
genrule(
name = "chartables",
srcs = ["pcre_chartables.c.dist"],
outs = ["pcre_chartables.c"],
cmd = "cp $< $@",
)
""",
strip_prefix = "pcre-8.43",
urls = [
"https://mirror.bazel.build/ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz",
"https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz",
],
sha256 = "0b8e7465dc5e98c757cc3650a20a7843ee4c3edf50aaf60bb33fd879690d2c73",
)
# pcre source code repository
http_archive(
name = "pcre2",
build_file = "//bazel:pcre2.BUILD",
patches = ["//bazel:pcre2.patch"],
strip_prefix = "pcre2-10.42",
urls = [
"https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.42/pcre2-10.42.tar.gz",
],
sha256 = "c33b418e3b936ee3153de2c61cc638e7e4fe3156022a5c77d0711bcbb9d64f1f",
)
http_archive(
name = "rules_m4",
sha256 = "b0309baacfd1b736ed82dc2bb27b0ec38455a31a3d5d20f8d05e831ebeef1a8e",
urls = ["https://github.com/jmillikin/rules_m4/releases/download/v0.2.2/rules_m4-v0.2.2.tar.xz"],
)
load("@rules_m4//m4:m4.bzl", "m4_register_toolchains")
m4_register_toolchains()
http_archive(
name = "rules_bison",
urls = ["https://github.com/jmillikin/rules_bison/releases/download/v0.2.1/rules_bison-v0.2.1.tar.xz"],
sha256 = "9577455967bfcf52f9167274063ebb74696cb0fd576e4226e14ed23c5d67a693",
)
load("@rules_bison//bison:bison.bzl", "bison_register_toolchains")
bison_register_toolchains()
new_git_repository(
name = "swig",
build_file = "//bazel:swig.BUILD",
tag = "v4.0.2",
patches = ["//bazel:swig.patch"],
patch_args = ["-p1"],
tag = "v4.1.1",
remote = "https://github.com/swig/swig.git",
)

View File

@@ -14,10 +14,13 @@
exports_files([
"gtest.BUILD",
"glpk.BUILD",
"pcre2.BUILD",
"pcre2.patch",
"re2.patch",
"swig.BUILD",
"scip.BUILD",
"scip.patch",
"swig.BUILD",
"swig.patch",
"bliss.BUILD",
"bliss-0.73.patch",
# "zlib.BUILD",
@@ -26,7 +29,7 @@ exports_files([
])
sh_binary(
name = "mkdir_wrapper",
srcs = ["mkdir_wrapper.sh"],
name = "run_swig",
srcs = ["run_swig.sh"],
visibility = ["//visibility:public"],
)

72
bazel/pcre2.BUILD Normal file
View File

@@ -0,0 +1,72 @@
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
copy_file(
name = "config_h_generic",
src = "src/config.h.generic",
out = "src/config.h",
)
copy_file(
name = "pcre2_h_generic",
src = "src/pcre2.h.generic",
out = "src/pcre2.h",
)
copy_file(
name = "pcre2_chartables_c",
src = "src/pcre2_chartables.c.dist",
out = "src/pcre2_chartables.c",
)
cc_library(
name = "pcre2",
srcs = [
"src/pcre2_auto_possess.c",
"src/pcre2_compile.c",
"src/pcre2_config.c",
"src/pcre2_context.c",
"src/pcre2_convert.c",
"src/pcre2_dfa_match.c",
"src/pcre2_error.c",
"src/pcre2_extuni.c",
"src/pcre2_find_bracket.c",
"src/pcre2_maketables.c",
"src/pcre2_match.c",
"src/pcre2_match_data.c",
"src/pcre2_newline.c",
"src/pcre2_ord2utf.c",
"src/pcre2_pattern_info.c",
"src/pcre2_script_run.c",
"src/pcre2_serialize.c",
"src/pcre2_string_utils.c",
"src/pcre2_study.c",
"src/pcre2_substitute.c",
"src/pcre2_substring.c",
"src/pcre2_tables.c",
"src/pcre2_ucd.c",
"src/pcre2_ucptables.c",
"src/pcre2_valid_utf.c",
"src/pcre2_xclass.c",
":pcre2_chartables_c",
],
hdrs = glob(["src/*.h"]) + [
":config_h_generic",
":pcre2_h_generic",
],
defines = [
"HAVE_CONFIG_H",
"PCRE2_CODE_UNIT_WIDTH=8",
"PCRE2_STATIC",
],
includes = ["src"],
strip_include_prefix = "src",
visibility = ["//visibility:public"],
)
cc_binary(
name = "pcre2demo",
srcs = ["src/pcre2demo.c"],
visibility = ["//visibility:public"],
deps = [":pcre2"],
)

13
bazel/pcre2.patch Normal file
View File

@@ -0,0 +1,13 @@
--- /dev/null 2022-12-31 10:33:36
+++ WORKSPACE 2022-12-31 10:31:42
@@ -0,0 +1,10 @@
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
+
+# Bazel Skylib rules.
+git_repository(
+ name = "bazel_skylib",
+ tag = "1.2.1",
+ remote = "https://github.com/bazelbuild/bazel-skylib.git",
+)
+load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
+bazel_skylib_workspace()

View File

@@ -19,9 +19,4 @@
#
# This is to work around https://github.com/bazelbuild/bazel/issues/6393
readonly directory="$1"
readonly command="$2"
shift 2
mkdir -p "${directory}"
exec "${command}" "$@"
exec swig "$@"

View File

@@ -5,69 +5,94 @@ exports_files(["LICENSE"])
cc_binary(
name = "swig",
srcs = [
"Source/CParse/cparse.h",
"Source/CParse/cscanner.c",
"Source/CParse/parser.c",
"Source/CParse/parser.h",
"Source/CParse/templ.c",
"Source/CParse/util.c",
"Source/DOH/base.c",
"Source/DOH/doh.h",
"Source/Include/swigconfig.h",
"Source/DOH/dohint.h",
"Source/DOH/file.c",
"Source/DOH/fio.c",
"Source/DOH/hash.c",
"Source/DOH/doh.h",
"Source/Swig/swigfile.h",
"Source/Swig/swigtree.h",
"Source/Swig/swig.h",
"Source/Swig/swigparm.h",
"Source/Swig/swigwrap.h",
"Source/Swig/swigscan.h",
"Source/Swig/swigopt.h",
"Source/Include/swigwarn.h",
"Source/CParse/parser.h",
"Source/CParse/cparse.h",
"Source/Doxygen/doxycommands.h",
"Source/Doxygen/doxyentity.h",
"Source/Doxygen/javadoc.h",
"Source/Doxygen/doxytranslator.h",
"Source/Doxygen/doxyparser.h",
"Source/Doxygen/pydoc.h",
"Source/Modules/swigmod.h",
"Source/Preprocessor/preprocessor.h",
"Source/DOH/list.c",
"Source/DOH/memory.c",
"Source/DOH/base.c",
"Source/DOH/string.c",
"Source/DOH/hash.c",
"Source/DOH/fio.c",
"Source/DOH/void.c",
"Source/Include/swigconfig.h",
"Source/Include/swigwarn.h",
"Source/Modules/allocate.cxx",
"Source/Modules/browser.cxx",
"Source/Modules/contract.cxx",
"Source/Modules/directors.cxx",
"Source/Modules/emit.cxx",
"Source/Modules/lang.cxx",
"Source/Modules/main.cxx",
"Source/Modules/module.cxx",
"Source/Modules/nested.cxx",
"Source/Modules/overload.cxx",
"Source/Modules/python.cxx",
"Source/Modules/swigmain-lite.cxx",
"Source/Modules/swigmod.h",
"Source/Modules/typepass.cxx",
"Source/Modules/uffi.cxx",
"Source/Modules/utils.cxx",
"Source/Modules/xml.cxx",
"Source/Preprocessor/cpp.c",
"Source/Preprocessor/expr.c",
"Source/Preprocessor/preprocessor.h",
"Source/Swig/cwrap.c",
"Source/Swig/deprecate.c",
"Source/Swig/error.c",
"Source/Swig/extend.c",
"Source/DOH/file.c",
"Source/Swig/scanner.c",
"Source/Swig/fragment.c",
"Source/Swig/getopt.c",
"Source/Swig/include.c",
"Source/Swig/misc.c",
"Source/Swig/typesys.c",
"Source/Swig/naming.c",
"Source/Swig/parms.c",
"Source/Swig/scanner.c",
"Source/Swig/stype.c",
"Source/Swig/swig.h",
"Source/Swig/swigfile.h",
"Source/Swig/swigopt.h",
"Source/Swig/swigparm.h",
"Source/Swig/swigscan.h",
"Source/Swig/swigtree.h",
"Source/Swig/swigwrap.h",
"Source/Swig/symbol.c",
"Source/Swig/tree.c",
"Source/Swig/deprecate.c",
"Source/Swig/extend.c",
"Source/Swig/typemap.c",
"Source/Swig/typeobj.c",
"Source/Swig/typesys.c",
"Source/Swig/error.c",
"Source/Swig/wrapfunc.c",
"Source/Swig/symbol.c",
"Source/Swig/stype.c",
"Source/Swig/cwrap.c",
"Source/Swig/include.c",
"Source/Swig/typeobj.c",
"Source/Swig/misc.c",
"Source/Swig/getopt.c",
"Source/Swig/tree.c",
"Source/CParse/templ.c",
"Source/CParse/util.c",
"Source/CParse/cscanner.c",
"Source/CParse/parser.c",
"Source/Preprocessor/cpp.c",
"Source/Preprocessor/expr.c",
"Source/Doxygen/doxytranslator.cxx",
"Source/Doxygen/javadoc.cxx",
"Source/Doxygen/doxyparser.cxx",
"Source/Doxygen/doxyentity.cxx",
"Source/Doxygen/pydoc.cxx",
"Source/Modules/nested.cxx",
"Source/Modules/python.cxx",
"Source/Modules/ruby.cxx",
"Source/Modules/main.cxx",
"Source/Modules/lang.cxx",
"Source/Modules/lua.cxx",
"Source/Modules/mzscheme.cxx",
"Source/Modules/tcl8.cxx",
"Source/Modules/xml.cxx",
"Source/Modules/javascript.cxx",
"Source/Modules/directors.cxx",
"Source/Modules/allocate.cxx",
"Source/Modules/interface.cxx",
"Source/Modules/java.cxx",
"Source/Modules/emit.cxx",
"Source/Modules/swigmain.cxx",
"Source/Modules/go.cxx",
"Source/Modules/csharp.cxx",
"Source/Modules/d.cxx",
"Source/Modules/typepass.cxx",
"Source/Modules/contract.cxx",
"Source/Modules/ocaml.cxx",
"Source/Modules/overload.cxx",
"Source/Modules/perl5.cxx",
"Source/Modules/r.cxx",
"Source/Modules/octave.cxx",
"Source/Modules/utils.cxx",
"Source/Modules/guile.cxx",
"Source/Modules/scilab.cxx",
"Source/Modules/php.cxx",
],
copts = ["$(STACK_FRAME_UNLIMITED)"] + select({
":x64_windows_msvc": [],
@@ -81,6 +106,7 @@ cc_binary(
includes = [
"Source/CParse",
"Source/DOH",
"Source/Doxygen",
"Source/Include",
"Source/Modules",
"Source/Preprocessor",
@@ -88,196 +114,18 @@ cc_binary(
],
output_licenses = ["unencumbered"],
visibility = ["//visibility:public"],
deps = ["@pcre"],
deps = ["@pcre2//:pcre2"],
)
filegroup(
name = "templates",
srcs = [
"Lib/allkw.swg",
"Lib/attribute.i",
"Lib/carrays.i",
"Lib/cdata.i",
"Lib/cffi/cffi.swg",
"Lib/cmalloc.i",
"Lib/constraints.i",
"Lib/cpointer.i",
"Lib/cstring.i",
"Lib/cwstring.i",
"Lib/exception.i",
"Lib/intrusive_ptr.i",
"Lib/inttypes.i",
"Lib/linkruntime.c",
"Lib/math.i",
"Lib/pointer.i",
"Lib/python/argcargv.i",
"Lib/python/attribute.i",
"Lib/python/boost_shared_ptr.i",
"Lib/python/builtin.swg",
"Lib/python/carrays.i",
"Lib/python/ccomplex.i",
"Lib/python/cdata.i",
"Lib/python/cmalloc.i",
"Lib/python/cni.i",
"Lib/python/complex.i",
"Lib/python/cpointer.i",
"Lib/python/cstring.i",
"Lib/python/cwstring.i",
"Lib/python/defarg.swg",
"Lib/python/director.swg",
"Lib/python/embed.i",
"Lib/python/embed15.i",
"Lib/python/exception.i",
"Lib/python/factory.i",
"Lib/python/file.i",
"Lib/python/implicit.i",
"Lib/python/jstring.i",
"Lib/python/pyabc.i",
"Lib/python/pyapi.swg",
"Lib/python/pybackward.swg",
"Lib/python/pybuffer.i",
"Lib/python/pyclasses.swg",
"Lib/python/pycomplex.swg",
"Lib/python/pycontainer.swg",
"Lib/python/pydocs.swg",
"Lib/python/pyerrors.swg",
"Lib/python/pyfragments.swg",
"Lib/python/pyhead.swg",
"Lib/python/pyinit.swg",
"Lib/python/pyiterators.swg",
"Lib/python/pymacros.swg",
"Lib/python/pyname_compat.i",
"Lib/python/pyopers.swg",
"Lib/python/pyprimtypes.swg",
"Lib/python/pyrun.swg",
"Lib/python/pyruntime.swg",
"Lib/python/pystdcommon.swg",
"Lib/python/pystrings.swg",
"Lib/python/python.swg",
"Lib/python/pythonkw.swg",
"Lib/python/pythreads.swg",
"Lib/python/pytuplehlp.swg",
"Lib/python/pytypemaps.swg",
"Lib/python/pyuserdir.swg",
"Lib/python/pywstrings.swg",
"Lib/python/std_alloc.i",
"Lib/python/std_auto_ptr.i",
"Lib/python/std_basic_string.i",
"Lib/python/std_carray.i",
"Lib/python/std_char_traits.i",
"Lib/python/std_common.i",
"Lib/python/std_complex.i",
"Lib/python/std_container.i",
"Lib/python/std_deque.i",
"Lib/python/std_except.i",
"Lib/python/std_ios.i",
"Lib/python/std_iostream.i",
"Lib/python/std_list.i",
"Lib/python/std_map.i",
"Lib/python/std_multimap.i",
"Lib/python/std_multiset.i",
"Lib/python/std_pair.i",
"Lib/python/std_set.i",
"Lib/python/std_shared_ptr.i",
"Lib/python/std_sstream.i",
"Lib/python/std_streambuf.i",
"Lib/python/std_string.i",
"Lib/python/std_unordered_map.i",
"Lib/python/std_unordered_multimap.i",
"Lib/python/std_unordered_multiset.i",
"Lib/python/std_unordered_set.i",
"Lib/python/std_vector.i",
"Lib/python/std_vectora.i",
"Lib/python/std_wios.i",
"Lib/python/std_wiostream.i",
"Lib/python/std_wsstream.i",
"Lib/python/std_wstreambuf.i",
"Lib/python/std_wstring.i",
"Lib/python/stl.i",
"Lib/python/typemaps.i",
"Lib/python/wchar.i",
"Lib/runtime.swg",
"Lib/shared_ptr.i",
"Lib/std/_std_deque.i",
"Lib/std/std_alloc.i",
"Lib/std/std_basic_string.i",
"Lib/std/std_carray.swg",
"Lib/std/std_char_traits.i",
"Lib/std/std_common.i",
"Lib/std/std_container.i",
"Lib/std/std_deque.i",
"Lib/std/std_except.i",
"Lib/std/std_ios.i",
"Lib/std/std_iostream.i",
"Lib/std/std_list.i",
"Lib/std/std_map.i",
"Lib/std/std_multimap.i",
"Lib/std/std_multiset.i",
"Lib/std/std_pair.i",
"Lib/std/std_queue.i",
"Lib/std/std_set.i",
"Lib/std/std_sstream.i",
"Lib/std/std_stack.i",
"Lib/std/std_streambuf.i",
"Lib/std/std_string.i",
"Lib/std/std_unordered_map.i",
"Lib/std/std_unordered_multimap.i",
"Lib/std/std_unordered_multiset.i",
"Lib/std/std_unordered_set.i",
"Lib/std/std_vector.i",
"Lib/std/std_vectora.i",
"Lib/std/std_wios.i",
"Lib/std/std_wiostream.i",
"Lib/std/std_wsstream.i",
"Lib/std/std_wstreambuf.i",
"Lib/std/std_wstring.i",
"Lib/std_except.i",
"Lib/stdint.i",
"Lib/stl.i",
"Lib/swig.swg",
"Lib/swigarch.i",
"Lib/swigerrors.swg",
"Lib/swiginit.swg",
"Lib/swiglabels.swg",
"Lib/swigrun.i",
"Lib/swigrun.swg",
"Lib/swigwarn.swg",
"Lib/swigwarnings.swg",
"Lib/typemaps/attribute.swg",
"Lib/typemaps/carrays.swg",
"Lib/typemaps/cdata.swg",
"Lib/typemaps/cmalloc.swg",
"Lib/typemaps/cpointer.swg",
"Lib/typemaps/cstring.swg",
"Lib/typemaps/cstrings.swg",
"Lib/typemaps/cwstring.swg",
"Lib/typemaps/enumint.swg",
"Lib/typemaps/exception.swg",
"Lib/typemaps/factory.swg",
"Lib/typemaps/fragments.swg",
"Lib/typemaps/implicit.swg",
"Lib/typemaps/inoutlist.swg",
"Lib/typemaps/misctypes.swg",
"Lib/typemaps/primtypes.swg",
"Lib/typemaps/ptrtypes.swg",
"Lib/typemaps/std_except.swg",
"Lib/typemaps/std_string.swg",
"Lib/typemaps/std_strings.swg",
"Lib/typemaps/std_wstring.swg",
"Lib/typemaps/string.swg",
"Lib/typemaps/strings.swg",
"Lib/typemaps/swigmacros.swg",
"Lib/typemaps/swigobject.swg",
"Lib/typemaps/swigtype.swg",
"Lib/typemaps/swigtypemaps.swg",
"Lib/typemaps/traits.swg",
"Lib/typemaps/typemaps.swg",
"Lib/typemaps/valtypes.swg",
"Lib/typemaps/void.swg",
"Lib/typemaps/wstring.swg",
"Lib/wchar.i",
"Lib/windows.i",
],
srcs = glob([
'Lib/*',
'Lib/python/*',
'Lib/std/*',
'Lib/java/*',
'Lib/typemaps/*'
]),
licenses = ["notice"], # simple notice license for Lib/
path = "Lib",
visibility = ["//visibility:public"],
@@ -291,7 +139,7 @@ genrule(
"#define HAVE_PCRE\n" +
"#define HAVE_POPEN\n" +
"#define PACKAGE_BUGREPORT \"http://www.swig.org\"\n" +
"#define PACKAGE_VERSION \"3.0.12\"\n" +
"#define PACKAGE_VERSION \"4.1.1\"\n" +
"#define STDC_HEADERS\n" +
"#define SWIG_CXX \"bazel4lyfe\"\n" +
"#define SWIG_LIB \"external/swig/Lib\"\n" +
@@ -300,36 +148,6 @@ genrule(
"EOF",
)
genrule(
name = "get_rid_of_stuff_we_dont_need_yet",
srcs = ["Source/Modules/swigmain.cxx"],
outs = ["Source/Modules/swigmain-lite.cxx"],
cmd = "sed -e '/swig_allegrocl/d'" +
" -e '/swig_cffi/d'" +
" -e '/swig_chicken/d'" +
" -e '/swig_clisp/d'" +
" -e '/swig_csharp/d'" +
" -e '/swig_d/d'" +
" -e '/swig_go/d'" +
" -e '/swig_guile/d'" +
" -e '/swig_java/d'" +
" -e '/swig_lua/d'" +
" -e '/swig_modula3/d'" +
" -e '/swig_mzscheme/d'" +
" -e '/swig_ocaml/d'" +
" -e '/swig_octave/d'" +
" -e '/swig_perl/d'" +
" -e '/swig_php/d'" +
" -e '/swig_pike/d'" +
" -e '/swig_r/d'" +
" -e '/swig_ruby/d'" +
" -e '/swig_scilab/d'" +
" -e '/swig_sexp/d'" +
" -e '/swig_tcl/d'" +
" -e '/swig_uffi/d'" +
" $< >$@",
)
config_setting(
name = "x64_windows_msvc",
values = {"cpu": "x64_windows_msvc"},

13513
bazel/swig.patch Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -51,8 +51,6 @@ def _java_wrap_cc_impl(ctx):
java_files_dir = ctx.actions.declare_directory("java_files")
swig_args = ctx.actions.args()
swig_args.add_all([java_files_dir], expand_directories = False)
swig_args.add("swig")
swig_args.add("-c++")
swig_args.add("-java")
swig_args.add("-package", ctx.attr.package)
@@ -72,7 +70,7 @@ def _java_wrap_cc_impl(ctx):
ctx.actions.run(
outputs = generated_c_files + [java_files_dir],
inputs = depset([src] + ctx.files.swig_includes, transitive = header_sets),
executable = ctx.executable._mkdir_wrapper,
executable = ctx.executable._swig,
arguments = [swig_args],
mnemonic = "SwigCompile",
)
@@ -120,8 +118,8 @@ It's expected that the `swig` binary exists in the host's path.
default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
providers = [java_common.JavaRuntimeInfo],
),
"_mkdir_wrapper": attr.label(
default = Label("//bazel:mkdir_wrapper"),
"_swig": attr.label(
default = Label("//bazel:run_swig"),
executable = True,
cfg = "exec",
),