diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml new file mode 100644 index 0000000..734a7fe --- /dev/null +++ b/.bazelci/presubmit.yml @@ -0,0 +1,13 @@ +--- +tasks: + ubuntu2004: + name: Ubuntu 20.04 + platform: ubuntu2004 + working_directory: e2e/workspace + test_targets: + - "//..." + +buildifier: + version: "6.1.0" + # keep this argument in sync with .pre-commit-config.yaml + warnings: "all" diff --git a/.bazelversion b/.bazelversion index d635c73..86d00b9 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1,4 +1,4 @@ -5.2.0 +5.4.0 # The first line of this file is used by Bazelisk and Bazel to be sure # the right version of Bazel is used to build and test this repo. # This also defines which version is used on CI. diff --git a/.github/workflows/ci.bazelrc b/.github/workflows/ci.bazelrc index a21ece4..8d50544 100644 --- a/.github/workflows/ci.bazelrc +++ b/.github/workflows/ci.bazelrc @@ -11,3 +11,7 @@ build --repository_cache=~/.cache/bazel-repo test --test_output=errors # Allows tests to run bazelisk-in-bazel, since this is the cache folder used test --test_env=XDG_CACHE_HOME + +# Prevent cache miss due to different environment variables between runs +build --incompatible_strict_action_env +test --incompatible_strict_action_env diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cc3a2fd..9dd4bb9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,7 +20,6 @@ jobs: strategy: matrix: folder: - - '.' - 'e2e/workspace' # Steps represent a sequence of tasks that will be executed as part of the job @@ -42,8 +41,8 @@ jobs: uses: actions/cache@v3 with: path: | - "~/.cache/bazel" - "~/.cache/bazel-repo" + ~/.cache/bazel + ~/.cache/bazel-repo key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }} restore-keys: bazel-cache- - name: bazel test //... diff --git a/NOTES b/NOTES new file mode 100644 index 0000000..5cee234 --- /dev/null +++ b/NOTES @@ -0,0 +1,13 @@ +resolve TODOs + +have requirements.txt in rules_qt repo, not e2e, and call the pip repo rules_qt_pip + +replacement of "-config" files breaks llvm-config, see https://github.com/bazelbuild/rules_foreign_cc/pull/109. commit bf2cb01 +llvm-config --ldflags will refer to an old sandbox. This was solved for libpng and freetype by replacing the -config file, but they were ascii scripts, not executables! could use it if no-sandbox for llvm build, but try mesa without llvm-config + +could try to change replace_in_files to only do so if "file " result contains "ascii" + +Add the following to Bazel rc and use Bazel 6.0 to see if it prevents llvm being built twice - https://github.com/bazelbuild/bazel/issues/14023#issuecomment-1325718022 + +See if qt cmake variable can be set to not build the docs and therefore not require llvm + diff --git a/WORKSPACE b/WORKSPACE index 09316b0..d5476fe 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -11,7 +11,7 @@ rules_qt_internal_deps() load("//qt:repositories.bzl", "rules_qt_dependencies") # Fetch dependencies which users need as well -rules_qt_dependencies() +rules_qt_dependencies(qt_version = "6.2.4") # For running our own unit tests load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") diff --git a/e2e/workspace/.bazelrc b/e2e/workspace/.bazelrc index e69de29..ada7d26 100644 --- a/e2e/workspace/.bazelrc +++ b/e2e/workspace/.bazelrc @@ -0,0 +1,5 @@ +#build --noincompatible_enable_cc_toolchain_resolution +#build --override_repository=mesa=/home/jheaffey/git/mesa +#build --override_repository=rules_foreign_cc=/home/jheaffey/git/rules_foreign_cc + + diff --git a/e2e/workspace/.bazelversion b/e2e/workspace/.bazelversion new file mode 100644 index 0000000..1e20ec3 --- /dev/null +++ b/e2e/workspace/.bazelversion @@ -0,0 +1 @@ +5.4.0 \ No newline at end of file diff --git a/e2e/workspace/BUILD b/e2e/workspace/BUILD index 4c39e33..97c4dd6 100644 --- a/e2e/workspace/BUILD +++ b/e2e/workspace/BUILD @@ -1,17 +1,8 @@ -"""Provides a simple way to test your rules as an external workspace. -Add a basic smoke-test target below. -""" - load("@bazel_skylib//rules:build_test.bzl", "build_test") -# load("rules_qt//qt:defs.bzl", "...") - -# Replace with a usage of your rule/macro -filegroup(name = "empty") build_test( - name = "smoke_test", + name = "qt_build_test", targets = [ - # targets you add above - ":empty", + "@qt//:qt", ], ) diff --git a/e2e/workspace/WORKSPACE b/e2e/workspace/WORKSPACE index 0dce389..ac777b9 100644 --- a/e2e/workspace/WORKSPACE +++ b/e2e/workspace/WORKSPACE @@ -4,5 +4,24 @@ local_repository( path = "../..", ) +# (copied from https://github.com/tensorflow/tensorflow/blob/58e320bee974240b4193ffe7da7bc1cc1c43a551/WORKSPACE#L5) +# The cascade of load() statements and rules_qt_dependencies?() calls works around the +# restriction that load() statements need to be at the top of .bzl files. +# E.g. we can not retrieve a new repository with http_archive and then load() +# a macro from that repository in the same file. + load("@rules_qt//qt:repositories.bzl", "rules_qt_dependencies") -rules_qt_dependencies() + +rules_qt_dependencies(qt_version = "6.2.4") + +load("@rules_qt//qt:repositories2.bzl", "rules_qt_dependencies2") + +rules_qt_dependencies2() + +load("@rules_qt//qt:repositories3.bzl", "rules_qt_dependencies3") + +rules_qt_dependencies3() + +load("@rules_qt//qt:repositories4.bzl", "rules_qt_dependencies4") + +rules_qt_dependencies4() diff --git a/e2e/workspace/requirements.txt b/e2e/workspace/requirements.txt new file mode 100644 index 0000000..fc61d10 --- /dev/null +++ b/e2e/workspace/requirements.txt @@ -0,0 +1 @@ +mako==1.2.1 diff --git a/e2e/workspace/requirements_lock.txt b/e2e/workspace/requirements_lock.txt new file mode 100644 index 0000000..fc580a9 --- /dev/null +++ b/e2e/workspace/requirements_lock.txt @@ -0,0 +1,52 @@ +# +# This file is autogenerated by pip-compile with python 3.9 +# To update, run: +# +# bazel run //:requirements.update +# +mako==1.2.1 \ + --hash=sha256:df3921c3081b013c8a2d5ff03c18375651684921ae83fd12e64800b7da923257 \ + --hash=sha256:f054a5ff4743492f1aa9ecc47172cb33b42b9d993cffcc146c9de17e717b0307 + # via -r requirements.txt +markupsafe==2.1.1 \ + --hash=sha256:0212a68688482dc52b2d45013df70d169f542b7394fc744c02a57374a4207003 \ + --hash=sha256:089cf3dbf0cd6c100f02945abeb18484bd1ee57a079aefd52cffd17fba910b88 \ + --hash=sha256:10c1bfff05d95783da83491be968e8fe789263689c02724e0c691933c52994f5 \ + --hash=sha256:33b74d289bd2f5e527beadcaa3f401e0df0a89927c1559c8566c066fa4248ab7 \ + --hash=sha256:3799351e2336dc91ea70b034983ee71cf2f9533cdff7c14c90ea126bfd95d65a \ + --hash=sha256:3ce11ee3f23f79dbd06fb3d63e2f6af7b12db1d46932fe7bd8afa259a5996603 \ + --hash=sha256:421be9fbf0ffe9ffd7a378aafebbf6f4602d564d34be190fc19a193232fd12b1 \ + --hash=sha256:43093fb83d8343aac0b1baa75516da6092f58f41200907ef92448ecab8825135 \ + --hash=sha256:46d00d6cfecdde84d40e572d63735ef81423ad31184100411e6e3388d405e247 \ + --hash=sha256:4a33dea2b688b3190ee12bd7cfa29d39c9ed176bda40bfa11099a3ce5d3a7ac6 \ + --hash=sha256:4b9fe39a2ccc108a4accc2676e77da025ce383c108593d65cc909add5c3bd601 \ + --hash=sha256:56442863ed2b06d19c37f94d999035e15ee982988920e12a5b4ba29b62ad1f77 \ + --hash=sha256:671cd1187ed5e62818414afe79ed29da836dde67166a9fac6d435873c44fdd02 \ + --hash=sha256:694deca8d702d5db21ec83983ce0bb4b26a578e71fbdbd4fdcd387daa90e4d5e \ + --hash=sha256:6a074d34ee7a5ce3effbc526b7083ec9731bb3cbf921bbe1d3005d4d2bdb3a63 \ + --hash=sha256:6d0072fea50feec76a4c418096652f2c3238eaa014b2f94aeb1d56a66b41403f \ + --hash=sha256:6fbf47b5d3728c6aea2abb0589b5d30459e369baa772e0f37a0320185e87c980 \ + --hash=sha256:7f91197cc9e48f989d12e4e6fbc46495c446636dfc81b9ccf50bb0ec74b91d4b \ + --hash=sha256:86b1f75c4e7c2ac2ccdaec2b9022845dbb81880ca318bb7a0a01fbf7813e3812 \ + --hash=sha256:8dc1c72a69aa7e082593c4a203dcf94ddb74bb5c8a731e4e1eb68d031e8498ff \ + --hash=sha256:8e3dcf21f367459434c18e71b2a9532d96547aef8a871872a5bd69a715c15f96 \ + --hash=sha256:8e576a51ad59e4bfaac456023a78f6b5e6e7651dcd383bcc3e18d06f9b55d6d1 \ + --hash=sha256:96e37a3dc86e80bf81758c152fe66dbf60ed5eca3d26305edf01892257049925 \ + --hash=sha256:97a68e6ada378df82bc9f16b800ab77cbf4b2fada0081794318520138c088e4a \ + --hash=sha256:99a2a507ed3ac881b975a2976d59f38c19386d128e7a9a18b7df6fff1fd4c1d6 \ + --hash=sha256:a49907dd8420c5685cfa064a1335b6754b74541bbb3706c259c02ed65b644b3e \ + --hash=sha256:b09bf97215625a311f669476f44b8b318b075847b49316d3e28c08e41a7a573f \ + --hash=sha256:b7bd98b796e2b6553da7225aeb61f447f80a1ca64f41d83612e6139ca5213aa4 \ + --hash=sha256:b87db4360013327109564f0e591bd2a3b318547bcef31b468a92ee504d07ae4f \ + --hash=sha256:bcb3ed405ed3222f9904899563d6fc492ff75cce56cba05e32eff40e6acbeaa3 \ + --hash=sha256:d4306c36ca495956b6d568d276ac11fdd9c30a36f1b6eb928070dc5360b22e1c \ + --hash=sha256:d5ee4f386140395a2c818d149221149c54849dfcfcb9f1debfe07a8b8bd63f9a \ + --hash=sha256:dda30ba7e87fbbb7eab1ec9f58678558fd9a6b8b853530e176eabd064da81417 \ + --hash=sha256:e04e26803c9c3851c931eac40c695602c6295b8d432cbe78609649ad9bd2da8a \ + --hash=sha256:e1c0b87e09fa55a220f058d1d49d3fb8df88fbfab58558f1198e08c1e1de842a \ + --hash=sha256:e72591e9ecd94d7feb70c1cbd7be7b3ebea3f548870aa91e2732960fa4d57a37 \ + --hash=sha256:e8c843bbcda3a2f1e3c2ab25913c80a3c5376cd00c6e8c4a86a89a28c8dc5452 \ + --hash=sha256:efc1913fd2ca4f334418481c7e595c00aad186563bbc1ec76067848c7ca0a933 \ + --hash=sha256:f121a1420d4e173a5d96e47e9a0c0dcff965afdf1626d28de1460815f7c4ee7a \ + --hash=sha256:fc7b548b17d238737688817ab67deebb30e8073c95749d55538ed473130ec0c7 + # via mako diff --git a/qt/private/host_python2.bzl b/qt/private/host_python2.bzl new file mode 100644 index 0000000..e09358b --- /dev/null +++ b/qt/private/host_python2.bzl @@ -0,0 +1,66 @@ +load(":versions.bzl", "DEPS") + +def __host_python2_impl_windows(rctx): + msiexec = rctx.which("msiexec.exe") + if not msiexec: + fail("Unable to find msiexec.exe") + + rctx.report_progress("Fetching python2 MSI") + + rctx.download(**DEPS["python2-windows"]) + + msi_name = DEPS["python2-windows"]["output"] + msi_path = str(rctx.path(msi_name)).replace("/", "\\") # why is this necessary? (copied from rules 7zip) + + # msiexec seems to not like extracting to the current working directory, so extract to a folder named "python2" + msi_target_dir = "python2" + msi_target_path = str(rctx.path("python2")).replace("/", "\\") # why is this necessary? (copied from rules 7zip) + + msi_extract_args = [ + msiexec, + "/a", + msi_path, + "TARGETDIR=%s" % msi_target_path, + "/qn", + ] + + rctx.report_progress("Extracting %s" % msi_path) + msi_extract_result = rctx.execute(msi_extract_args) + + if msi_extract_result.return_code != 0: + err_message = msi_extract_result.stdout if msi_extract_result.stdout else msi_extract_result.stderr + fail("Python2 MSI extraction failed: exit_code=%s\n\n%s" % (msi_extract_result.return_code, err_message)) + + exec_python2_path = rctx.path("python2/python.exe") + + if not exec_python2_path.exists: + fail("Missing %s after MSI extraction" % exec_python2_path) + + rctx.template( + "BUILD", + Label("//third_party/python2:BUILD.python2_windows.bazel.tpl"), + {"%{target_dir}": msi_target_dir}, + ) + +def __host_python2_impl_linux(rctx): + rctx.download_and_extract(**DEPS["python2-src"]) + rctx.file( + "BUILD", + rctx.read(Label("//third_party/python2:BUILD.python2_linux.bazel")), + ) + +def _host_python2_impl(rctx): + """ Implementation of the host_python2 repository rule.""" + + if rctx.os.name.startswith("windows"): + __host_python2_impl_windows(rctx) + else: + __host_python2_impl_linux(rctx) + +host_python2 = repository_rule( + implementation = _host_python2_impl, + doc = + """ + Download python2 msi file and extract it .TODO - some doc here. say why necessary, namely pip_install python_interpreter_target must be a file, not a build output + """, +) diff --git a/qt/private/http_archive.bzl b/qt/private/http_archive.bzl new file mode 100644 index 0000000..1be11f3 --- /dev/null +++ b/qt/private/http_archive.bzl @@ -0,0 +1,327 @@ +# Copyright 2016 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +Fork of the @bazel_tools//tools/build_defs/repo:http.bzl to provide a http_archive +rule which can inject files into the created repository + +Upstream code is at +https://github.com/bazelbuild/bazel/blob/5.2.0/tools/build_defs/repo/http.bzl + +""" + +load( + "@bazel_tools//tools/build_defs/repo:utils.bzl", + "patch", + "read_netrc", + "read_user_netrc", + "update_attrs", + "use_netrc", + "workspace_and_buildfile", +) + +# Shared between http_jar, http_file and http_archive. +_AUTH_PATTERN_DOC = """An optional dict mapping host names to custom authorization patterns. + +If a URL's host name is present in this dict the value will be used as a pattern when +generating the authorization header for the http request. This enables the use of custom +authorization schemes used in a lot of common cloud storage providers. + +The pattern currently supports 2 tokens: <login> and +<password>, which are replaced with their equivalent value +in the netrc file for the same host name. After formatting, the result is set +as the value for the Authorization field of the HTTP request. + +Example attribute and netrc for a http download to an oauth2 enabled API using a bearer token: + +
+auth_patterns = {
+    "storage.cloudprovider.com": "Bearer <password>"
+}
+
+ +netrc: + +
+machine storage.cloudprovider.com
+        password RANDOM-TOKEN
+
+ +The final HTTP request would have the following header: + +
+Authorization: Bearer RANDOM-TOKEN
+
+""" + +def _get_auth(ctx, urls): + """Given the list of URLs obtain the correct auth dict.""" + if ctx.attr.netrc: + netrc = read_netrc(ctx, ctx.attr.netrc) + else: + netrc = read_user_netrc(ctx) + return use_netrc(netrc, urls, ctx.attr.auth_patterns) + +def _http_archive_impl(ctx): + """Implementation of the http_archive rule.""" + if not ctx.attr.url and not ctx.attr.urls: + fail("At least one of url and urls must be provided") + if ctx.attr.build_file and ctx.attr.build_file_content: + fail("Only one of build_file and build_file_content can be provided.") + + for label in ctx.attr.additional_files: + additional_file_stripped = label.name.split(ctx.attr.additional_files[label] + "/")[1] + ctx.file(additional_file_stripped, ctx.read(label)) + + all_urls = [] + if ctx.attr.urls: + all_urls = ctx.attr.urls + if ctx.attr.url: + all_urls = [ctx.attr.url] + all_urls + + auth = _get_auth(ctx, all_urls) + + download_info = ctx.download_and_extract( + all_urls, + "", + ctx.attr.sha256, + ctx.attr.type, + ctx.attr.strip_prefix, + canonical_id = ctx.attr.canonical_id, + auth = auth, + integrity = ctx.attr.integrity, + ) + workspace_and_buildfile(ctx) + patch(ctx, auth = auth) + + # We don't need to override the sha256 attribute if integrity is already specified. + sha256_override = {} if ctx.attr.integrity else {"sha256": download_info.sha256} + return update_attrs(ctx.attr, _http_archive_attrs.keys(), sha256_override) + +_http_archive_attrs = { + "url": attr.string( + doc = + """A URL to a file that will be made available to Bazel. + +This must be a file, http or https URL. Redirections are followed. +Authentication is not supported. + +This parameter is to simplify the transition from the native http_archive +rule. More flexibility can be achieved by the urls parameter that allows +to specify alternative URLs to fetch from. +""", + ), + "urls": attr.string_list( + doc = + """A list of URLs to a file that will be made available to Bazel. + +Each entry must be a file, http or https URL. Redirections are followed. +Authentication is not supported. + +URLs are tried in order until one succeeds, so you should list local mirrors first. +If all downloads fail, the rule will fail.""", + ), + "sha256": attr.string( + doc = """The expected SHA-256 of the file downloaded. + +This must match the SHA-256 of the file downloaded. _It is a security risk +to omit the SHA-256 as remote files can change._ At best omitting this +field will make your build non-hermetic. It is optional to make development +easier but either this attribute or `integrity` should be set before shipping.""", + ), + "integrity": attr.string( + doc = """Expected checksum in Subresource Integrity format of the file downloaded. + +This must match the checksum of the file downloaded. _It is a security risk +to omit the checksum as remote files can change._ At best omitting this +field will make your build non-hermetic. It is optional to make development +easier but either this attribute or `sha256` should be set before shipping.""", + ), + "netrc": attr.string( + doc = "Location of the .netrc file to use for authentication", + ), + "auth_patterns": attr.string_dict( + doc = _AUTH_PATTERN_DOC, + ), + "canonical_id": attr.string( + doc = """A canonical id of the archive downloaded. + +If specified and non-empty, bazel will not take the archive from cache, +unless it was added to the cache by a request with the same canonical id. +""", + ), + "strip_prefix": attr.string( + doc = """A directory prefix to strip from the extracted files. + +Many archives contain a top-level directory that contains all of the useful +files in archive. Instead of needing to specify this prefix over and over +in the `build_file`, this field can be used to strip it from all of the +extracted files. + +For example, suppose you are using `foo-lib-latest.zip`, which contains the +directory `foo-lib-1.2.3/` under which there is a `WORKSPACE` file and are +`src/`, `lib/`, and `test/` directories that contain the actual code you +wish to build. Specify `strip_prefix = "foo-lib-1.2.3"` to use the +`foo-lib-1.2.3` directory as your top-level directory. + +Note that if there are files outside of this directory, they will be +discarded and inaccessible (e.g., a top-level license file). This includes +files/directories that start with the prefix but are not in the directory +(e.g., `foo-lib-1.2.3.release-notes`). If the specified prefix does not +match a directory in the archive, Bazel will return an error.""", + ), + "type": attr.string( + doc = """The archive type of the downloaded file. + +By default, the archive type is determined from the file extension of the +URL. If the file has no extension, you can explicitly specify one of the +following: `"zip"`, `"jar"`, `"war"`, `"aar"`, `"tar"`, `"tar.gz"`, `"tgz"`, +`"tar.xz"`, `"txz"`, `"tar.zst"`, `"tzst"`, `tar.bz2`, `"ar"`, or `"deb"`.""", + ), + "patches": attr.label_list( + default = [], + doc = + "A list of files that are to be applied as patches after " + + "extracting the archive. By default, it uses the Bazel-native patch implementation " + + "which doesn't support fuzz match and binary patch, but Bazel will fall back to use " + + "patch command line tool if `patch_tool` attribute is specified or there are " + + "arguments other than `-p` in `patch_args` attribute.", + ), + "remote_patches": attr.string_dict( + default = {}, + doc = + "A map of patch file URL to its integrity value, they are applied after extracting " + + "the archive and before applying patch files from the `patches` attribute. " + + "It uses the Bazel-native patch implementation, you can specify the patch strip " + + "number with `remote_patch_strip`", + ), + "remote_patch_strip": attr.int( + default = 0, + doc = + "The number of leading slashes to be stripped from the file name in the remote patches.", + ), + "patch_tool": attr.string( + default = "", + doc = "The patch(1) utility to use. If this is specified, Bazel will use the specifed " + + "patch tool instead of the Bazel-native patch implementation.", + ), + "patch_args": attr.string_list( + default = ["-p0"], + doc = + "The arguments given to the patch tool. Defaults to -p0, " + + "however -p1 will usually be needed for patches generated by " + + "git. If multiple -p arguments are specified, the last one will take effect." + + "If arguments other than -p are specified, Bazel will fall back to use patch " + + "command line tool instead of the Bazel-native patch implementation. When falling " + + "back to patch command line tool and patch_tool attribute is not specified, " + + "`patch` will be used. This only affects patch files in the `patches` attribute.", + ), + "patch_cmds": attr.string_list( + default = [], + doc = "Sequence of Bash commands to be applied on Linux/Macos after patches are applied.", + ), + "patch_cmds_win": attr.string_list( + default = [], + doc = "Sequence of Powershell commands to be applied on Windows after patches are " + + "applied. If this attribute is not set, patch_cmds will be executed on Windows, " + + "which requires Bash binary to exist.", + ), + "build_file": attr.label( + allow_single_file = True, + doc = + "The file to use as the BUILD file for this repository." + + "This attribute is an absolute label (use '@//' for the main " + + "repo). The file does not need to be named BUILD, but can " + + "be (something like BUILD.new-repo-name may work well for " + + "distinguishing it from the repository's actual BUILD files. " + + "Either build_file or build_file_content can be specified, but " + + "not both.", + ), + "build_file_content": attr.string( + doc = + "The content for the BUILD file for this repository. " + + "Either build_file or build_file_content can be specified, but " + + "not both.", + ), + "workspace_file": attr.label( + doc = + "The file to use as the `WORKSPACE` file for this repository. " + + "Either `workspace_file` or `workspace_file_content` can be " + + "specified, or neither, but not both.", + ), + "workspace_file_content": attr.string( + doc = + "The content for the WORKSPACE file for this repository. " + + "Either `workspace_file` or `workspace_file_content` can be " + + "specified, or neither, but not both.", + ), + "additional_files": attr.label_keyed_string_dict( + default = {}, + doc = + "A dict of {label: strip_prefix} for files that should be added to the repository." + + "This is a workaround to the fact that the native patch implementation cannot add new files", + ), +} + +http_archive = repository_rule( + implementation = _http_archive_impl, + attrs = _http_archive_attrs, + doc = + """Downloads a Bazel repository as a compressed archive file, decompresses it, +and makes its targets available for binding. + +It supports the following file extensions: `"zip"`, `"jar"`, `"war"`, `"aar"`, `"tar"`, +`"tar.gz"`, `"tgz"`, `"tar.xz"`, `"txz"`, `"tar.zst"`, `"tzst"`, `tar.bz2`, `"ar"`, +or `"deb"`. + +Examples: + Suppose the current repository contains the source code for a chat program, + rooted at the directory `~/chat-app`. It needs to depend on an SSL library + which is available from http://example.com/openssl.zip. This `.zip` file + contains the following directory structure: + + ``` + WORKSPACE + src/ + openssl.cc + openssl.h + ``` + + In the local repository, the user creates a `openssl.BUILD` file which + contains the following target definition: + + ```python + cc_library( + name = "openssl-lib", + srcs = ["src/openssl.cc"], + hdrs = ["src/openssl.h"], + ) + ``` + + Targets in the `~/chat-app` repository can depend on this target if the + following lines are added to `~/chat-app/WORKSPACE`: + + ```python + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + + http_archive( + name = "my_ssl", + urls = ["http://example.com/openssl.zip"], + sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + build_file = "@//:openssl.BUILD", + ) + ``` + + Then targets would specify `@my_ssl//:openssl-lib` as a dependency. +""", +) diff --git a/qt/private/versions.bzl b/qt/private/versions.bzl index 7f6c5bd..27f5227 100644 --- a/qt/private/versions.bzl +++ b/qt/private/versions.bzl @@ -1,14 +1,19 @@ -"""Mirror of release info - -TODO: generate this file from GitHub API""" +""" This file lists supported Qt versions and their sha256 hashes """ # The integrity hashes can be computed with -# shasum -b -a 384 [downloaded file] | awk '{ print $1 }' | xxd -r -p | base64 -TOOL_VERSIONS = { - "1.14.2": { - "x86_64-apple-darwin": "sha384-ws4+rANvv0YxM1SgIBUXSG9jT8dKw83nls6R5qYkEKzPUB+viBIEozSsyq2e6i+f", - "aarch64-apple-darwin": "sha384-HcvJbxoJtGSavkGu0e7CyD00cBlmDb0TBWJ4JSaNa70zuU3N7XlMOYm3bbQcAv2U", - "x86_64-pc-windows-msvc": "sha384-35YN6TKpT0L9qyRBmq48NucvyXEtHnkeC+txf2YZmmJTmOzrAKREA74BA0EZvpar", - "x86_64-unknown-linux-gnu": "sha384-QgGOwTaetxY0h5HWCKc/3ZtBs4N/fgaaORthn7UcEv++Idm9W+ntCCZRwvBdwHPD", +QT_VERSIONS = { + "6.2.4": "cfe41905b6bde3712c65b102ea3d46fc80a44c9d1487669f14e4a6ee82ebb8fd", +} + +DEPS = { + "python2-windows": { + "url": "https://www.python.org/ftp/python/2.7.18/python-2.7.18.amd64.msi", + "sha256": "b74a3afa1e0bf2a6fc566a7b70d15c9bfabba3756fb077797d16fffa27800c05", + "output": "python-2.7.18.amd64.msi", + }, + "python2-src": { + "url": "https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz", + "sha256": "da3080e3b488f648a3d7a4560ddee895284c3380b11d6de75edb986526b9a814", + "stripPrefix": "Python-2.7.18", }, } diff --git a/qt/repositories.bzl b/qt/repositories.bzl index 68157d9..7eb8e35 100644 --- a/qt/repositories.bzl +++ b/qt/repositories.bzl @@ -6,7 +6,11 @@ See https://docs.bazel.build/versions/main/skylark/deploying.html#dependencies load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load("//qt/private:versions.bzl", "TOOL_VERSIONS") +load("//qt/private:versions.bzl", "QT_VERSIONS") +load("//qt/private:http_archive.bzl", custom_http_archive = "http_archive") +load("//qt/private:host_python2.bzl", "host_python2") +load("//third_party/autotools:repositories.bzl", "autotools_repositories") +load("//third_party/xorg:repositories.bzl", "xorg_repositories") # WARNING: any changes in this function may be BREAKING CHANGES for users # because we'll fetch a dependency which may be different from one that @@ -14,7 +18,7 @@ load("//qt/private:versions.bzl", "TOOL_VERSIONS") # ours took precedence. Such breakages are challenging for users, so any # changes in this function should be marked as BREAKING in the commit message # and released only in semver majors. -def rules_qt_dependencies(): +def rules_qt_dependencies(qt_version): # The minimal version of bazel_skylib we require maybe( http_archive, @@ -25,3 +29,224 @@ def rules_qt_dependencies(): "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz", ], ) + + qt_version_major, qt_version_minor, _ = qt_version.split(".") + maybe( + http_archive, + name = "qt", + build_file = Label("//third_party/qt:BUILD.qt.bazel"), + sha256 = QT_VERSIONS[qt_version], + strip_prefix = "qt-everywhere-src-{}".format(qt_version), + url = "https://download.qt.io/official_releases/qt/{major}.{minor}/{full}/single/qt-everywhere-src-{full}.tar.xz".format(major = qt_version_major, minor = qt_version_minor, full = qt_version), + ) + + maybe( + http_archive, + name = "rules_python", + sha256 = "a3a6e99f497be089f81ec082882e40246bfd435f52f4e82f37e89449b04573f6", + strip_prefix = "rules_python-0.10.2", + url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.10.2.tar.gz", + ) + + host_python2(name = "python2") + + maybe( + http_archive, + name = "rules_perl", + sha256 = "5cefadbf2a49bf3421ede009f2c5a2c9836abae792620ed2ff99184133755325", + strip_prefix = "rules_perl-0.1.0", + urls = [ + "https://github.com/bazelbuild/rules_perl/archive/refs/tags/0.1.0.tar.gz", + ], + ) + + # maybe( + # http_archive, + # name = "rules_foreign_cc", + # sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51", + # strip_prefix = "rules_foreign_cc-0.9.0", + # url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz", + # ) + + maybe( + http_archive, + name = "rules_foreign_cc", + sha256 = "0dd8a75428c52f4ed069c2aaec9b9666e5f6578e002d8ab85292cba3dc09a81f", + strip_prefix = "rules_foreign_cc-add_meson_support_tidy", + url = "https://github.com/jheaff1/rules_foreign_cc/archive/refs/heads/add_meson_support_tidy.zip", + ) + + maybe( + http_archive, + name = "build_bazel_rules_nodejs", + sha256 = "c78216f5be5d451a42275b0b7dc809fb9347e2b04a68f68bad620a2b01f5c774", + urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.2/rules_nodejs-5.5.2.tar.gz"], + ) + + maybe( + http_archive, + name = "vcpkg", + build_file = Label("//third_party/vcpkg:BUILD.vcpkg.bazel"), + sha256 = "099d473823bfa4c1b876ec5f99dc1f0d89da44f58557acff3eaee79335510086", + strip_prefix = "vcpkg-2022.06.16.1", + url = "https://github.com/microsoft/vcpkg/archive/refs/tags/2022.06.16.1.tar.gz", + ) + + maybe( + custom_http_archive, + name = "gperf", + additional_files = { + "@vcpkg//:ports/gperf/CMakeLists.txt": "ports/gperf", + "@vcpkg//:ports/gperf/config.h.in": "ports/gperf", + }, + build_file = Label("//third_party/gperf:BUILD.gperf.bazel"), + # Patch injects files used by vcpkg to build gperf. The files are obtained from https://github.com/microsoft/vcpkg/tree/2022.06.16.1/ports/gperf + # patches = ["//third_party/gperf:gperf.patch"], + # According to http_archive documentation, any patch_args other than "-p" will force bazel to use command line tool "patch" rather than its java implementation. + # As the java implementation does not support creating new files via a patch, add an arbitrary arg so that the command linen tool is used instead + # patch_args = ["-s"], + sha256 = "588546b945bba4b70b6a3a616e80b4ab466e3f33024a352fc2198112cdbb3ae2", + strip_prefix = "gperf-3.1", + url = "http://ftp.gnu.org/pub/gnu/gperf/gperf-3.1.tar.gz", + ) + + maybe( + http_archive, + name = "bison", + build_file = Label("//third_party/bison:BUILD.bison.bazel"), + sha256 = "06c9e13bdf7eb24d4ceb6b59205a4f67c2c7e7213119644430fe82fbd14a0abb", + strip_prefix = "bison-3.8.2", + url = "https://ftp.gnu.org/gnu/bison/bison-3.8.2.tar.gz", + ) + + maybe( + http_archive, + name = "flex", + build_file = Label("//third_party/flex:BUILD.flex.bazel"), + sha256 = "e87aae032bf07c26f85ac0ed3250998c37621d95f8bd748b31f15b33c45ee995", + strip_prefix = "flex-2.6.4", + url = "https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz", + ) + + maybe( + http_archive, + name = "openssl", + build_file = Label("//third_party/openssl:BUILD.openssl.bazel"), + sha256 = "9384a2b0570dd80358841464677115df785edb941c71211f75076d72fe6b438f", + strip_prefix = "openssl-1.1.1o", + urls = [ + "https://mirror.bazel.build/www.openssl.org/source/openssl-1.1.1o.tar.gz", + "https://www.openssl.org/source/openssl-1.1.1o.tar.gz", + "https://github.com/openssl/openssl/archive/OpenSSL_1_1_1o.tar.gz", + ], + ) + + maybe( + http_archive, + name = "zlib", + build_file = Label("//third_party/zlib:BUILD.zlib.bazel"), + sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1", + strip_prefix = "zlib-1.2.11", + urls = [ + "https://zlib.net/zlib-1.2.11.tar.gz", + "https://storage.googleapis.com/mirror.tensorflow.org/zlib.net/zlib-1.2.11.tar.gz", + ], + ) + + # TODO build mesa with llvm-pipe + maybe( + http_archive, + name = "mesa", + build_file = Label("//third_party/mesa:BUILD.mesa.bazel"), + patches = [ + # This patch is required for meson to find the hermetic python interpreter + Label("//third_party/mesa:mesa.meson.build.patch"), + # The following patches are required so that dependencies are hermetically tracked by meson + Label("//third_party/mesa:mesa.src_loader_meson.build.patch"), + Label("//third_party/mesa:mesa.src_intel_vulkan_meson.build.patch"), + Label("//third_party/mesa:mesa.src_vulkan_util_meson.build.patch"), + Label("//third_party/mesa:mesa.src_gbm_meson.build.patch"), + Label("//third_party/mesa:mesa.src_gallium_frontends_dri_meson.build.patch"), + Label("//third_party/mesa:mesa.src_gallium_targets_dri_meson.build.patch"), + Label("//third_party/mesa:mesa.src_egl_meson.build.patch"), + Label("//third_party/mesa:mesa.src_glx_meson.build.patch"), + # This patch is required for mesa to build on MacOS + Label("//third_party/mesa:mesa.src_gallium_frontends_dri_dri_util.c.patch"), + ], + sha256 = "670d8cbe8b72902a45ea2da68a9da4dc4a5d99c5953a926177adbce1b1640b76", + strip_prefix = "mesa-22.1.4", + url = "https://archive.mesa3d.org/mesa-22.1.4.tar.xz", + ) + + maybe( + http_archive, + name = "libdrm", + build_file = Label("//third_party/libdrm:BUILD.libdrm.bazel"), + sha256 = "00b07710bd09b35cd8d80eaf4f4497fe27f4becf467a9830f1f5e8324f8420ff", + strip_prefix = "libdrm-2.4.112", + url = "https://dri.freedesktop.org/libdrm/libdrm-2.4.112.tar.xz", + ) + maybe( + http_archive, + name = "expat", + build_file = Label("//third_party/expat:BUILD.expat.bazel"), + sha256 = "a00ae8a6b96b63a3910ddc1100b1a7ef50dc26dceb65ced18ded31ab392f132b", + strip_prefix = "expat-2.4.1", + urls = [ + "https://mirror.bazel.build/github.com/libexpat/libexpat/releases/download/R_2_4_1/expat-2.4.1.tar.gz", + "https://github.com/libexpat/libexpat/releases/download/R_2_4_1/expat-2.4.1.tar.gz", + ], + ) + + maybe( + http_archive, + name = "libpciaccess", + build_file = Label("//third_party/libpciaccess:BUILD.libpciaccess.bazel"), + sha256 = "84413553994aef0070cf420050aa5c0a51b1956b404920e21b81e96db6a61a27", + strip_prefix = "libpciaccess-0.16", + url = "https://www.x.org/archive//individual/lib/libpciaccess-0.16.tar.gz", + ) + + maybe( + http_archive, + name = "apr", + build_file = Label("//third_party/apr:BUILD.apr.bazel"), + patches = [ + # https://bz.apache.org/bugzilla/show_bug.cgi?id=50146 + Label("//third_party/apr:macos_iovec.patch"), + # https://bz.apache.org/bugzilla/show_bug.cgi?id=64753 + Label("//third_party/apr:macos_pid_t.patch"), + # https://apachelounge.com/viewtopic.php?t=8260 + Label("//third_party/apr:windows_winnt.patch"), + ], + sha256 = "48e9dbf45ae3fdc7b491259ffb6ccf7d63049ffacbc1c0977cced095e4c2d5a2", + strip_prefix = "apr-1.7.0", + urls = [ + "https://mirror.bazel.build/www-eu.apache.org/dist/apr/apr-1.7.0.tar.gz", + "https://www-eu.apache.org/dist/apr/apr-1.7.0.tar.gz", + ], + ) + + maybe( + http_archive, + name = "llvm", + build_file = Label("//third_party/llvm:BUILD.llvm.bazel"), + sha256 = "8b3cfd7bc695bd6cea0f37f53f0981f34f87496e79e2529874fd03a2f9dd3a8a", + strip_prefix = "llvm-project-14.0.6.src", + url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.6/llvm-project-14.0.6.src.tar.xz", + ) + + maybe( + http_archive, + name = "libelf", + build_file = Label("//third_party/libelf:BUILD.libelf.bazel"), + sha256 = "591a9b4ec81c1f2042a97aa60564e0cb79d041c52faa7416acb38bc95bd2c76d", + strip_prefix = "libelf-0.8.13", + url = "https://fossies.org/linux/misc/old/libelf-0.8.13.tar.gz", + ) + + + autotools_repositories() + xorg_repositories() + + diff --git a/qt/repositories2.bzl b/qt/repositories2.bzl new file mode 100644 index 0000000..b4f29d0 --- /dev/null +++ b/qt/repositories2.bzl @@ -0,0 +1,34 @@ +"""Run dependency workspace macros + +A separate macro "rules_qt_extra_dependencies" is required as the "load" function can only be used at the top of a bzl file + +""" + +load("@rules_python//python:repositories.bzl", "python_register_toolchains") +load("@rules_perl//perl:deps.bzl", "perl_register_toolchains", "perl_rules_dependencies") +load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") +load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies") + + +# TODO have a boolean to register toolchains? + +def rules_qt_dependencies2(): + +# Perhaps need to pass in a boolean as to whether to run this, as it may have been run already? +#https://github.com/grpc/grpc/blob/1d8fac36b3914fc17296158d4cb90b3fe51f4654/bazel/grpc_deps.bzl#L537 +# Or perhaps just dont worry about it, seems that grpc doesnt worry about it, it just means that +# toolchains could be registered twice.? + python_register_toolchains( + name = "python3_9", + # Available versions are listed in @rules_python//python:versions.bzl. + # We recommend using the same version your team is already standardized on. + python_version = "3.9", + ) + + perl_rules_dependencies() + perl_register_toolchains() + + # TODO set register_built_pkgconfig_toolchain = True + rules_foreign_cc_dependencies() + + build_bazel_rules_nodejs_dependencies() diff --git a/qt/repositories3.bzl b/qt/repositories3.bzl new file mode 100644 index 0000000..5597f6e --- /dev/null +++ b/qt/repositories3.bzl @@ -0,0 +1,17 @@ +"""Run dependency workspace macros""" + +load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories") +load("@python3_9//:defs.bzl", py3_interpreter = "interpreter") +load("@rules_python//python:pip.bzl", "pip_parse") + +def rules_qt_dependencies3(): + # Note that node_repositories creates a nodejs_toolchains repo + node_repositories( + node_version = "18.5.0", + ) + + pip_parse( + name = "rules_qt_pip", + python_interpreter_target = py3_interpreter, + requirements_lock = "//:requirements_lock.txt", + ) diff --git a/qt/repositories4.bzl b/qt/repositories4.bzl new file mode 100644 index 0000000..43d2b7d --- /dev/null +++ b/qt/repositories4.bzl @@ -0,0 +1,7 @@ +"""Run dependency workspace macros""" + +load("@rules_qt_pip//:requirements.bzl", "install_deps") + +def rules_qt_dependencies4(): + install_deps() + diff --git a/qt/tests/BUILD.bazel b/qt/tests/BUILD.bazel deleted file mode 100644 index 93eae3c..0000000 --- a/qt/tests/BUILD.bazel +++ /dev/null @@ -1,3 +0,0 @@ -load(":versions_test.bzl", "versions_test_suite") - -versions_test_suite(name = "versions_test") diff --git a/qt/tests/versions_test.bzl b/qt/tests/versions_test.bzl deleted file mode 100644 index b966a73..0000000 --- a/qt/tests/versions_test.bzl +++ /dev/null @@ -1,18 +0,0 @@ -"""Unit tests for starlark helpers -See https://docs.bazel.build/versions/main/skylark/testing.html#for-testing-starlark-utilities -""" - -load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") -load("//qt/private:versions.bzl", "TOOL_VERSIONS") - -def _smoke_test_impl(ctx): - env = unittest.begin(ctx) - asserts.equals(env, "1.14.2", TOOL_VERSIONS.keys()[0]) - return unittest.end(env) - -# The unittest library requires that we export the test cases as named test rules, -# but their names are arbitrary and don't appear anywhere. -_t0_test = unittest.make(_smoke_test_impl) - -def versions_test_suite(name): - unittest.suite(name, _t0_test) diff --git a/third_party/BUILD.bazel b/third_party/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/apr/BUILD.apr.bazel b/third_party/apr/BUILD.apr.bazel new file mode 100644 index 0000000..3d4a6ea --- /dev/null +++ b/third_party/apr/BUILD.apr.bazel @@ -0,0 +1,61 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make", "make_variant") + +LIB_NAME = "apr" + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +config_setting( + name = "msvc_compiler", + flag_values = { + "@bazel_tools//tools/cpp:compiler": "msvc-cl", + }, + visibility = ["//visibility:public"], +) + +alias( + name = "apr", + actual = select({ + ":msvc_compiler": "apr_msvc", + "//conditions:default": "apr_default", + }), + visibility = ["//visibility:public"], +) + +make_variant( + name = "apr_msvc", + args = [ + "-F Makefile.win", + "ARCH=\"x64 Release\"", + ], + lib_name = LIB_NAME, + lib_source = ":all_srcs", + out_static_libs = ["apr-1.lib"], + targets = [ + "buildall", + "install", + ], + toolchain = "@rules_foreign_cc//toolchains:preinstalled_nmake_toolchain", + visibility = ["//visibility:public"], +) + +configure_make( + name = "apr_default", + configure_in_place = True, + configure_options = [ + "--disable-shared", + ], + env = select({ + "@platforms//os:macos": {"AR": ""}, + "//conditions:default": {}, + }), + lib_name = LIB_NAME, + lib_source = ":all_srcs", + out_static_libs = ["libapr-1.a"], + visibility = ["//visibility:public"], +) diff --git a/third_party/apr/BUILD.bazel b/third_party/apr/BUILD.bazel new file mode 100644 index 0000000..638bde6 --- /dev/null +++ b/third_party/apr/BUILD.bazel @@ -0,0 +1,16 @@ +load("@bazel_skylib//rules:build_test.bzl", "build_test") + +exports_files( + [ + "BUILD.apr.bazel", + ], + visibility = ["//visibility:public"], +) + +build_test( + name = "apr_build_test", + targets = [ + "@apr//:apr", + ], + visibility = ["//:__pkg__"], +) diff --git a/third_party/apr/macos_iovec.patch b/third_party/apr/macos_iovec.patch new file mode 100644 index 0000000..31ef073 --- /dev/null +++ b/third_party/apr/macos_iovec.patch @@ -0,0 +1,97 @@ +diff -ruN configure configure +--- configure 2019-04-01 19:56:23.000000000 +0200 ++++ configure 2019-04-01 19:56:23.000000000 +0200 +@@ -24475,6 +24475,7 @@ + cat confdefs.h - <<_ACEOF >conftest.$ac_ext + /* end confdefs.h. */ + #include ++$ac_includes_default + #include + #ifdef WIN32 + #define binmode "b" +@@ -24485,7 +24486,7 @@ + { + FILE *f=fopen("conftestval", "w" binmode); + if (!f) exit(1); +- fprintf(f, "%d\n", sizeof(pid_t)); ++ fprintf(f, "%zd\n", sizeof(pid_t)); + exit(0); + } + _ACEOF +@@ -24800,6 +24801,7 @@ + cat confdefs.h - <<_ACEOF >conftest.$ac_ext + /* end confdefs.h. */ + #include ++$ac_includes_default + #include + #ifdef WIN32 + #define binmode "b" +@@ -24810,7 +24812,7 @@ + { + FILE *f=fopen("conftestval", "w" binmode); + if (!f) exit(1); +- fprintf(f, "%d\n", sizeof(ssize_t)); ++ fprintf(f, "%zd\n", sizeof(ssize_t)); + exit(0); + } + _ACEOF +@@ -24863,6 +24865,7 @@ + cat confdefs.h - <<_ACEOF >conftest.$ac_ext + /* end confdefs.h. */ + #include ++$ac_includes_default + #include + #ifdef WIN32 + #define binmode "b" +@@ -24873,7 +24876,7 @@ + { + FILE *f=fopen("conftestval", "w" binmode); + if (!f) exit(1); +- fprintf(f, "%d\n", sizeof(size_t)); ++ fprintf(f, "%zd\n", sizeof(size_t)); + exit(0); + } + _ACEOF +@@ -24927,6 +24930,7 @@ + cat confdefs.h - <<_ACEOF >conftest.$ac_ext + /* end confdefs.h. */ + #include ++$ac_includes_default + #include + #ifdef WIN32 + #define binmode "b" +@@ -24937,7 +24941,7 @@ + { + FILE *f=fopen("conftestval", "w" binmode); + if (!f) exit(1); +- fprintf(f, "%d\n", sizeof(off_t)); ++ fprintf(f, "%zd\n", sizeof(off_t)); + exit(0); + } + _ACEOF +@@ -25308,7 +25312,7 @@ + { + FILE *f=fopen("conftestval", "w" binmode); + if (!f) exit(1); +- fprintf(f, "%d\n", sizeof(ino_t)); ++ fprintf(f, "%zd\n", sizeof(ino_t)); + exit(0); + } + _ACEOF +@@ -25584,6 +25588,7 @@ + cat confdefs.h - <<_ACEOF >conftest.$ac_ext + /* end confdefs.h. */ + #include ++$ac_includes_default + #include + #include + #ifdef WIN32 +@@ -25595,7 +25600,7 @@ + { + FILE *f=fopen("conftestval", "w" binmode); + if (!f) exit(1); +- fprintf(f, "%d\n", sizeof(struct iovec)); ++ fprintf(f, "%zd\n", sizeof(struct iovec)); + exit(0); + } + _ACEOF diff --git a/third_party/apr/macos_pid_t.patch b/third_party/apr/macos_pid_t.patch new file mode 100644 index 0000000..d7e25cc --- /dev/null +++ b/third_party/apr/macos_pid_t.patch @@ -0,0 +1,12 @@ +diff -ruN configure configure +--- configure 2019-04-01 19:56:23.000000000 +0200 ++++ configure 2019-04-01 19:56:23.000000000 +0200 +@@ -24517,7 +24518,7 @@ + elif test "$ac_cv_sizeof_pid_t" = "$ac_cv_sizeof_long_long"; then + pid_t_fmt='#define APR_PID_T_FMT APR_INT64_T_FMT' + else +- pid_t_fmt='#error Can not determine the proper size for pid_t' ++ pid_t_fmt='#define APR_PID_T_FMT "d"' + fi + + # Basically, we have tried to figure out the correct format strings \ No newline at end of file diff --git a/third_party/apr/windows_winnt.patch b/third_party/apr/windows_winnt.patch new file mode 100644 index 0000000..ee67549 --- /dev/null +++ b/third_party/apr/windows_winnt.patch @@ -0,0 +1,11 @@ +--- include/apr.hw 2019-03-21 00:41:37.000000000 +0100 ++++ include/apr.hw 2019-03-21 00:41:37.000000000 +0100 +@@ -86,7 +86,7 @@ + + /* Restrict the server to a subset of Windows XP header files by default + */ +-#define _WIN32_WINNT 0x0501 ++#define _WIN32_WINNT 0x0600 + #endif + #ifndef NOUSER + #define NOUSER diff --git a/third_party/autotools/BUILD.bazel b/third_party/autotools/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/autotools/BUILD.m4.bazel b/third_party/autotools/BUILD.m4.bazel new file mode 100644 index 0000000..8250f02 --- /dev/null +++ b/third_party/autotools/BUILD.m4.bazel @@ -0,0 +1,30 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "m4", + env = select({ + "@platforms//os:macos": {"AR": ""}, + "//conditions:default": {}, + }), + lib_source = ":all_srcs", + out_binaries = [ + "m4", + ], +) + +filegroup( + name = "m4_exe", + srcs = [":m4"], + output_group = "m4", + visibility = ["//visibility:public"], +) diff --git a/third_party/autotools/repositories.bzl b/third_party/autotools/repositories.bzl new file mode 100644 index 0000000..d26d993 --- /dev/null +++ b/third_party/autotools/repositories.bzl @@ -0,0 +1,17 @@ +# buildifier: disable=module-docstring +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +# buildifier: disable=function-docstring +def autotools_repositories(): + maybe( + http_archive, + name = "m4", + build_file = Label("//third_party/autotools:BUILD.m4.bazel"), + strip_prefix = "m4-1.4.19", + urls = [ + "https://mirror.bazel.build/ftp.gnu.org/gnu/m4/m4-1.4.19.tar.xz", + "https://ftp.gnu.org/gnu/m4/m4-1.4.19.tar.xz", + ], + sha256 = "63aede5c6d33b6d9b13511cd0be2cac046f2e70fd0a07aa9573a04a82783af96", + ) diff --git a/third_party/bison/BUILD.bazel b/third_party/bison/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/bison/BUILD.bison.bazel b/third_party/bison/BUILD.bison.bazel new file mode 100644 index 0000000..0b90440 --- /dev/null +++ b/third_party/bison/BUILD.bison.bazel @@ -0,0 +1,50 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +# I tested and this builds for me on macOS and Linux, did not check Windows +configure_make( + name = "bison", + build_data = [ + "@m4", + ], + env = select({ + "@platforms//os:linux": { + "M4": "$$EXT_BUILD_DEPS$$/bin/m4/bin/m4", + }, + "@platforms//os:macos": { + "AR": "", + "M4": "$$EXT_BUILD_DEPS$$/bin/m4/bin/m4", + }, + "//conditions:default": {}, + }), + lib_source = ":all_srcs", + out_binaries = [ + "bison", + "yacc", + ], + # Bison depends on m4sugar.m4 in the "share" directory at runtime + out_data_dirs = ["share"], + out_static_libs = ["liby.a"], +) + +filegroup( + name = "gen_dir", + srcs = [":bison"], + output_group = "gen_dir", + visibility = ["//visibility:public"], +) + +filegroup( + name = "bison_exe", + srcs = [":bison"], + output_group = "bison", +) diff --git a/third_party/expat/BUILD.bazel b/third_party/expat/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/expat/BUILD.expat.bazel b/third_party/expat/BUILD.expat.bazel new file mode 100644 index 0000000..b8ca2d5 --- /dev/null +++ b/third_party/expat/BUILD.expat.bazel @@ -0,0 +1,51 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake", "configure_make") + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +LIB_NAME = "expat" + +alias( + name = "expat", + actual = select({ + "@apr//:msvc_compiler": "expat_msvc", + "//conditions:default": "expat_default", + }), + visibility = ["//visibility:public"], +) + +cmake( + name = "expat_msvc", + cache_entries = { + "CMAKE_BUILD_TYPE": "Release", + "EXPAT_MSVC_STATIC_CRT": "ON", + "EXPAT_SHARED_LIBS": "OFF", + }, + generate_args = ["-G\"NMake Makefiles\""], + lib_name = LIB_NAME, + lib_source = ":all_srcs", + out_static_libs = ["libexpatMT.lib"], +) + +configure_make( + name = "expat_default", + configure_options = [ + "--disable-shared", + "--without-docbook", + "--without-examples", + "--without-tests", + "CFLAGS='-fPIC'", + ], + env = select({ + "@platforms//os:macos": {"AR": ""}, + "//conditions:default": {}, + }), + lib_name = LIB_NAME, + lib_source = ":all_srcs", + out_static_libs = ["libexpat.a"], +) diff --git a/third_party/flex/BUILD.bazel b/third_party/flex/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/flex/BUILD.flex.bazel b/third_party/flex/BUILD.flex.bazel new file mode 100644 index 0000000..8a66cbb --- /dev/null +++ b/third_party/flex/BUILD.flex.bazel @@ -0,0 +1,24 @@ + +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "flex", + lib_source = ":all_srcs", + out_binaries = ["flex"], +) + +filegroup( + name = "flex_exe", + srcs = [":flex"], + output_group = "flex", +) diff --git a/third_party/gperf/BUILD.bazel b/third_party/gperf/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/gperf/BUILD.gperf.bazel b/third_party/gperf/BUILD.gperf.bazel new file mode 100644 index 0000000..2fac6de --- /dev/null +++ b/third_party/gperf/BUILD.gperf.bazel @@ -0,0 +1,30 @@ +# TODO this depends on m4 + +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +cmake( + name = "gperf", + lib_source = ":all_srcs", + generate_args = ["-GNinja"], + out_binaries = select({ + "@platforms//os:windows": ["gperf.exe"], + "//conditions:default": ["gperf"], + }), +) + +filegroup( + name = "gperf_exe", + srcs = [":gperf"], + # Extract gperf executable using output_group set by rules_foreign_cc + output_group = select({ + "@platforms//os:windows": "gperf.exe", + "//conditions:default": "gperf", + }), +) diff --git a/third_party/libdrm/BUILD.bazel b/third_party/libdrm/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/libdrm/BUILD.libdrm.bazel b/third_party/libdrm/BUILD.libdrm.bazel new file mode 100644 index 0000000..1d74cd0 --- /dev/null +++ b/third_party/libdrm/BUILD.libdrm.bazel @@ -0,0 +1,32 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "meson") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +meson( + name = "libdrm", + lib_source = ":all_srcs", + out_lib_dir = "lib/x86_64-linux-gnu", + out_shared_libs = [ + "libdrm_amdgpu.so", + "libdrm_amdgpu.so.1", + "libdrm_amdgpu.so.1.0.0", + "libdrm_intel.so", + "libdrm_intel.so.1", + "libdrm_intel.so.1.0.0", + "libdrm_nouveau.so", + "libdrm_nouveau.so.2", + "libdrm_nouveau.so.2.0.0", + "libdrm_radeon.so", + "libdrm_radeon.so.1", + "libdrm_radeon.so.1.0.1", + "libdrm.so", + "libdrm.so.2", + "libdrm.so.2.4.0", + ], + deps = ["@libpciaccess"], +) diff --git a/third_party/libelf/BUILD.bazel b/third_party/libelf/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/libelf/BUILD.libelf.bazel b/third_party/libelf/BUILD.libelf.bazel new file mode 100644 index 0000000..8dab2a6 --- /dev/null +++ b/third_party/libelf/BUILD.libelf.bazel @@ -0,0 +1,16 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "libelf", + lib_source = ":all_srcs", +) diff --git a/third_party/libpciaccess/BUILD.bazel b/third_party/libpciaccess/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/libpciaccess/BUILD.libpciaccess.bazel b/third_party/libpciaccess/BUILD.libpciaccess.bazel new file mode 100644 index 0000000..15f0216 --- /dev/null +++ b/third_party/libpciaccess/BUILD.libpciaccess.bazel @@ -0,0 +1,16 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "libpciaccess", + lib_source = ":all_srcs", +) diff --git a/third_party/llvm/BUILD.bazel b/third_party/llvm/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/llvm/BUILD.llvm.bazel b/third_party/llvm/BUILD.llvm.bazel new file mode 100644 index 0000000..ef5bac2 --- /dev/null +++ b/third_party/llvm/BUILD.llvm.bazel @@ -0,0 +1,114 @@ +# working one manually is +#cmake -DCMAKE_BUILD_TYPE=Release '-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra' -DLLVM_INCLUDE_TESTS=OFF '-DLLVM_TARGETS_TO_BUILD=X86;AMDGPU' -DCMAKE_INSTALL_PREFIX=/home/jheaffey/llvm-install -G Ninja .. +# cmake --build . --config Release --target 'tools/llvm-config/install/strip' -j4 + +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +# genrule( +# name = "cxx_var", +# outs = ["cxx_var.sh"], +# cmd = """ +# cat > $@ << EOF +# COMPILER=$$(basename \\$${CC}) +# if [[ \\$${COMPILER} == *gcc ]]; then +# CXX=\\$${COMPILER%gcc}g++ +# elif [[ \\$${COMPILER} == clang ]]; then +# CXX=\\$${COMPILER%clang}clang++ +# else +# CXX=\\$${CC} +# fi +# export CXX=c++ +# export CC=cc +# EOF +# """, +# ) + +cmake( + name = "llvm", + cache_entries = { + "CMAKE_BUILD_TYPE": "Release", + # "LLVM_BUILD_TOOLS": "OFF", + # "LLVM_BUILD_UTILS": "OFF", + "LLVM_ENABLE_PROJECTS": "clang;clang-tools-extra", + "LLVM_INCLUDE_TESTS": "OFF", + # May need AMDGU for mesa? + "LLVM_TARGETS_TO_BUILD": "X86;AMDGPU", + # "CMAKE_SHARED_LINKER_FLAGS": "", + # "CMAKE_EXE_LINKER_FLAGS": "", + # "CMAKE_AR": "", + # "CMAKE_RANLIB": "", + # "CMAKE_PREFIX_PATH": "", + + }, + #source $EXT_BUILD_ROOT/bazel-out/k8-opt-exec-2B5CBBC6/bin/external/llvm/cxx_var.sh && unset CFLAGS CXXFLAGS ASMFLAGS && $EXT_BUILD_ROOT/external/cmake-3.23.2-linux-x86_64/bin/cmake -DCMAKE_AR="/usr/bin/ar" -DCMAKE_SHARED_LINKER_FLAGS="-shared -lstdc++ -lm" -DCMAKE_EXE_LINKER_FLAGS="-lstdc++ -lm" -DCMAKE_BUILD_TYPE="Release" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DLLVM_INCLUDE_TESTS="OFF" -DLLVM_TARGETS_TO_BUILD="X86;AMDGPU" -DCMAKE_INSTALL_PREFIX="$INSTALLDIR" -DCMAKE_PREFIX_PATH="$EXT_BUILD_DEPS" -DCMAKE_RANLIB="" -DCMAKE_MAKE_PROGRAM=$EXT_BUILD_ROOT/external/ninja_1.11.0_linux/ninja -G 'Ninja' $EXT_BUILD_ROOT/external/llvm/llvm + # build_data = [":cxx_var"], + generate_args = ["-GNinja"], + generate_crosstool_file = False, + # Set to install to False otherwise all of LLVM will be built + install = False, + lib_source = ":all", + out_binaries = [ + "clang-format", + "clang-tidy", + # "llvm-config", + ], + # TODO remove + build_args=["-j6"], + # tags = ["no-sandbox"], + out_data_dirs = ["lib"], # required as clang-tidy needs the lib folder, which contains system includes like stddef.h + targets = [ + # "install-clang-format-stripped", + # "install-clang-tidy-stripped", + # "install-clang-resource-headers-stripped", # generate the lib folder in the installation directory, required by clang-tidy + + # # For mesa. instead could just build everything with install-distribution-stripped (i think) + # "install-LLVMAMDGPUAsmParser-stripped", + # "install-LLVMBitReader-stripped", + # "install-LLVMBitWriter-stripped", + # "install-LLVMCore-stripped", + # "install-LLVMExecutionEngine-stripped", + # "install-LLVMInstCombine-stripped", + # "install-LLVMipo-stripped", + # "install-LLVMMCDisassembler-stripped", + # "install-LLVMMCJIT-stripped", + # "install-LLVMScalarOpts-stripped", + # "install-LLVMTransformUtils-stripped", + # "install-LLVMCoroutines-stripped", + #"tools/install/strip", # TODO shouldnt be necessary when doingn install/strip + # "tools/llvm-config/install", + "install/strip", + # "install-distribution-stripped" + ], + working_directory = "llvm", + # tool_prefix="source $$EXT_BUILD_ROOT$$/$(location :cxx_var) && unset CFLAGS CXXFLAGS ASMFLAGS &&", + # features = ["-default_link_flags"], + # postfix_script = "ls -l $$BUILD_TMPDIR$$/bin/llvm-config && $$BUILD_TMPDIR$$/bin/llvm-config --version && ls -l $$INSTALLDIR$$ && ls -l $$INSTALLDIR$$/bin && rm -f $$INSTALLDIR$$/bin/llvm-config && cp $$BUILD_TMPDIR$$/bin/llvm-config $$INSTALLDIR$$/bin && ls -l $$INSTALLDIR$$/bin/llvm-config ", + # postfix_script = "$INSTALLDIR/bin/llvm-config && " +) + +# https://github.com/bazelbuild/rules_foreign_cc/blob/edbfa3bfa924d656f489428bdfec523d057be9bd/examples/cmake_hello_world_lib/binary/BUILD.bazel#L26 +# Seems like the way to get a binary as a standalone bazel target is using a filegroup +filegroup( + name = "clang_format", + srcs = [":llvm"], + output_group = "clang-format", +) + +filegroup( + name = "clang_tidy", + srcs = [":llvm"], + output_group = "clang-tidy", +) + +# filegroup( +# name = "llvm_config", +# srcs = [":llvm"], +# output_group = "llvm-config", +# ) diff --git a/third_party/mesa/BUILD.bazel b/third_party/mesa/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/mesa/BUILD.mesa.bazel b/third_party/mesa/BUILD.mesa.bazel new file mode 100644 index 0000000..c993c3f --- /dev/null +++ b/third_party/mesa/BUILD.mesa.bazel @@ -0,0 +1,157 @@ +load("@rules_qt_pip//:requirements.bzl", "requirement") +load("@rules_foreign_cc//foreign_cc:defs.bzl", "meson_with_requirements") + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +config_setting( + name = "msvc_compiler", + flag_values = { + "@bazel_tools//tools/cpp:compiler": "msvc-cl", + }, +) + +meson_with_requirements( + name = "mesa", + build_args = select({ + # Prevent parallel builds on when using winflexbison, due to issue https://github.com/lexxmark/winflexbison/issues/86 + "@bazel_tools//src/conditions:host_windows": ["-j 1"], + "//conditions:default": [], + }), + build_data = select({ + "@bazel_tools//src/conditions:host_windows": ["@winflexbison//:gen_dir"], + "//conditions:default": [ + "@bison//:gen_dir", + "@flex//:flex_exe", + # "@llvm", # llvm_config requires the lib dir generated by the llvm build + # "@llvm//:llvm_config", + "@m4//:m4_exe", + ], + }), + # this prevents the output directory being "mesa_", as meson_with_requirements defines the target to build as "mesa_" + lib_name = "mesa", + env = select({ + "@bazel_tools//src/conditions:host_windows": { + "PATH": "$$(dirname $$EXT_BUILD_ROOT$$/$(location @winflexbison//:gen_dir))/winflexbison:$$(dirname $$EXT_BUILD_ROOT$$/$(PYTHON3)):$$PATH", + }, + "//conditions:default": { + "BISON_PKGDATADIR": "$$(dirname $$EXT_BUILD_ROOT$$/$(location @bison//:gen_dir))/bison/share/bison", + "M4": "$$EXT_BUILD_ROOT$$/$(location @m4//:m4_exe)", + "PATH": "$$(dirname $$EXT_BUILD_ROOT$$/$(location @bison//:gen_dir))/bison/bin:$$(dirname $$EXT_BUILD_ROOT$$/$(location @flex//:flex_exe)):$$EXT_BUILD_DEPS$$/bin/m4/bin/:$$(dirname $$EXT_BUILD_ROOT$$/$(PYTHON3)):$$PATH", + "CMAKE_PREFIX_PATH": "$$EXT_BUILD_DEPS$$/llvm/lib/cmake/llvm", + }, + }), + options = select({ + "@platforms//os:linux": { + "shared-llvm": "disabled", + "cpp_rtti": "false", # Required because LVVM is built with LLVM_ENABLE_RTTI=OFF by default + "platforms": "x11", + }, + "//conditions:default": {}, + }), + lib_source = ":all_srcs", + out_interface_libs = select({ + ":msvc_compiler": [ + "libgallium_wgl.lib", + "opengl32.lib", + ], + "//conditions:default": [], + }), + out_lib_dir = select({ + "@platforms//os:linux": "lib/x86_64-linux-gnu", + "//conditions:default": "lib", + }), + out_shared_libs = select({ + ":msvc_compiler": [ + "libgallium_wgl.dll", + "opengl32.dll", + ], + "@platforms//os:linux": [ + "dri/crocus_dri.so", + "dri/i915_dri.so", + "dri/iris_dri.so", + "dri/kms_swrast_dri.so", + "dri/nouveau_dri.so", + "dri/r300_dri.so", + "dri/r600_dri.so", + "dri/radeonsi_dri.so", + "dri/swrast_dri.so", + "dri/virtio_gpu_dri.so", + "dri/vmwgfx_dri.so", + "libEGL.so", + "libEGL.so.1", + "libEGL.so.1.0.0", + "libgbm.so", + "libgbm.so.1", + "libgbm.so.1.0.0", + "libGL.so", + "libGL.so.1", + "libGL.so.1.2.0", + "libglapi.so", + "libglapi.so.0", + "libglapi.so.0.0.0", + "libGLESv1_CM.so", + "libGLESv1_CM.so.1", + "libGLESv1_CM.so.1.1.0", + "libGLESv2.so", + "libGLESv2.so.2", + "libGLESv2.so.2.0.0", + "libvulkan_intel.so", + "libvulkan_lvp.so", + "libvulkan_radeon.so", + "libxatracker.so", + "libxatracker.so.2", + "libxatracker.so.2.5.0", + ], + "@platforms//os:macos": [ + "libGLESv1_CM.1.dylib", + "libGL.dylib", + "libGLESv1_CM.dylib", + "libglapi.0.dylib", + "libglapi.dylib", + "libGLESv2.2.dylib", + "libGL.1.dylib", + "libGLESv2.dylib", + ], + }), + requirements = [ + requirement("mako"), + ], + # TODO - i added this as llvm-config had a segmentation fault. + tags = ["no-sandbox"], + toolchains = ["@rules_python//python:current_py_toolchain"], + visibility = ["//visibility:public"], + deps = select({ + "@platforms//os:linux": [ + "@bison", + "@expat", + "@libdrm", + "@libelf", + "@libpciaccess", + "@libxau", + "@libxcb", + "@libxdmcp", + "@libxext", + "@libxfixes", + "@libxrandr", + "@libxrender", + "@libxshmfence", + "@libXxf86vm", + "@libx11", + "@llvm", + "@xorgproto", + "@zlib", + ], + "@platforms//os:macos": [ + "@libxext", + "@libxfixes", + "@libx11", + "@zlib", + ], + "@platforms//os:windows": [ + "@zlib", + ], + }), +) diff --git a/third_party/mesa/blob b/third_party/mesa/blob new file mode 100644 index 0000000..e69de29 diff --git a/third_party/mesa/mesa.meson.build.patch b/third_party/mesa/mesa.meson.build.patch new file mode 100644 index 0000000..ff8960e --- /dev/null +++ b/third_party/mesa/mesa.meson.build.patch @@ -0,0 +1,19 @@ +--- meson.build 2022-07-15 18:42:47.000000000 +0100 ++++ meson.build 2022-11-30 17:26:50.607789896 +0000 +@@ -1002,7 +1002,7 @@ + ] + endif + +-prog_python = import('python').find_installation('python3') ++prog_python = import('python').find_installation() + has_mako = run_command( + prog_python, '-c', + ''' +@@ -2033,6 +2033,7 @@ + endif + + if with_platform_x11 ++ dep_x11 = dependency('x11') + if with_glx == 'xlib' or with_glx == 'gallium-xlib' + dep_x11 = dependency('x11') + dep_xext = dependency('xext') \ No newline at end of file diff --git a/third_party/mesa/mesa.src_egl_meson.build.patch b/third_party/mesa/mesa.src_egl_meson.build.patch new file mode 100644 index 0000000..4274e60 --- /dev/null +++ b/third_party/mesa/mesa.src_egl_meson.build.patch @@ -0,0 +1,11 @@ +--- src/egl/meson.build 2022-07-15 18:42:47.000000000 +0100 ++++ src/egl/meson.build 2022-12-05 14:21:05.700235372 +0000 +@@ -106,7 +106,7 @@ + files_egl += files('drivers/dri2/platform_x11_dri3.c') + link_for_egl += libloader_dri3_helper + endif +- deps_for_egl += [dep_x11_xcb, dep_xcb_dri2, dep_xcb_xfixes] ++ deps_for_egl += [dep_x11_xcb, dep_xcb_dri2, dep_xcb_xfixes, dep_xlib_xrandr] + endif + if with_gbm and not with_platform_android + files_egl += files('drivers/dri2/platform_drm.c') diff --git a/third_party/mesa/mesa.src_gallium_frontends_dri_dri_util.c.patch b/third_party/mesa/mesa.src_gallium_frontends_dri_dri_util.c.patch new file mode 100644 index 0000000..28f3080 --- /dev/null +++ b/third_party/mesa/mesa.src_gallium_frontends_dri_dri_util.c.patch @@ -0,0 +1,38 @@ +--- src/gallium/frontends/dri/dri_util.c 2022-07-15 18:42:47.000000000 +0100 ++++ src/gallium/frontends/dri/dri_util.c 2022-12-12 12:58:00.161799118 +0000 +@@ -171,6 +171,8 @@ + return psp; + } + ++#if defined(HAVE_LIBDRM) ++ + static __DRIscreen * + dri2CreateNewScreen(int scrn, int fd, + const __DRIextension **extensions, +@@ -191,6 +193,8 @@ + driver_configs, data); + } + ++#endif ++ + /** swrast driver createNewScreen entrypoint. */ + static __DRIscreen * + driSWRastCreateNewScreen(int scrn, const __DRIextension **extensions, +@@ -808,6 +812,8 @@ + .unbindContext = driUnbindContext + }; + ++#if defined(HAVE_LIBDRM) ++ + /** DRI2 interface */ + const __DRIdri2Extension driDRI2Extension = { + .base = { __DRI_DRI2, 4 }, +@@ -837,6 +843,8 @@ + .createNewScreen2 = driCreateNewScreen2, + }; + ++#endif ++ + const __DRIswrastExtension driSWRastExtension = { + .base = { __DRI_SWRAST, 4 }, + \ No newline at end of file diff --git a/third_party/mesa/mesa.src_gallium_frontends_dri_meson.build.patch b/third_party/mesa/mesa.src_gallium_frontends_dri_meson.build.patch new file mode 100644 index 0000000..2e97ec3 --- /dev/null +++ b/third_party/mesa/mesa.src_gallium_frontends_dri_meson.build.patch @@ -0,0 +1,12 @@ +--- src/gallium/frontends/dri/meson.build 2022-07-15 18:42:47.000000000 +0100 ++++ src/gallium/frontends/dri/meson.build 2022-12-05 13:22:50.210313339 +0000 +@@ -71,6 +71,9 @@ + dependencies : [ + dep_libdrm, + idep_mesautil, ++ dep_xcb, ++ dep_x11, ++ dep_xlib_xrandr + ], + ) + \ No newline at end of file diff --git a/third_party/mesa/mesa.src_gallium_targets_dri_meson.build.patch b/third_party/mesa/mesa.src_gallium_targets_dri_meson.build.patch new file mode 100644 index 0000000..db018b1 --- /dev/null +++ b/third_party/mesa/mesa.src_gallium_targets_dri_meson.build.patch @@ -0,0 +1,11 @@ +--- src/gallium/targets/dri/meson.build 2022-07-15 18:42:47.000000000 +0100 ++++ src/gallium/targets/dri/meson.build 2022-12-05 14:02:15.710260576 +0000 +@@ -58,7 +58,7 @@ + driver_kmsro, driver_v3d, driver_vc4, driver_freedreno, driver_etnaviv, + driver_tegra, driver_i915, driver_svga, driver_virgl, + driver_panfrost, driver_iris, driver_lima, driver_zink, driver_d3d12, +- driver_asahi, driver_crocus ++ driver_asahi, driver_crocus, dep_xcb, dep_x11, dep_xlib_xrandr + ], + # Will be deleted during installation, see install_megadrivers.py + install : true, diff --git a/third_party/mesa/mesa.src_gbm_meson.build.patch b/third_party/mesa/mesa.src_gbm_meson.build.patch new file mode 100644 index 0000000..091b07e --- /dev/null +++ b/third_party/mesa/mesa.src_gbm_meson.build.patch @@ -0,0 +1,13 @@ + +--- src/gbm/meson.build 2022-07-15 18:42:47.000000000 +0100 ++++ src/gbm/meson.build 2022-12-05 13:01:49.660341456 +0000 +@@ -44,6 +44,9 @@ + deps_gbm += dep_wayland_server + incs_gbm += inc_wayland_drm + endif ++if with_platform_x11 ++ deps_gbm += [dep_xcb, dep_x11, dep_xlib_xrandr] ++endif + + libgbm = shared_library( + 'gbm', diff --git a/third_party/mesa/mesa.src_glx_meson.build.patch b/third_party/mesa/mesa.src_glx_meson.build.patch new file mode 100644 index 0000000..8ffda0e --- /dev/null +++ b/third_party/mesa/mesa.src_glx_meson.build.patch @@ -0,0 +1,11 @@ +--- src/glx/meson.build 2022-07-15 18:42:47.000000000 +0100 ++++ src/glx/meson.build 2022-12-12 09:36:07.300346991 +0000 +@@ -136,7 +136,7 @@ + ], + dependencies : [ + idep_mesautil, idep_xmlconfig, +- dep_libdrm, dep_dri2proto, dep_glproto, dep_x11, dep_glvnd, ++ dep_libdrm, dep_dri2proto, dep_glproto, dep_x11, dep_glvnd, dep_xext, dep_xxf86vm, dep_xshmfence, dep_xlib_xrandr, dep_xfixes + ], + ) + diff --git a/third_party/mesa/mesa.src_intel_vulkan_meson.build.patch b/third_party/mesa/mesa.src_intel_vulkan_meson.build.patch new file mode 100644 index 0000000..f6e2f1b --- /dev/null +++ b/third_party/mesa/mesa.src_intel_vulkan_meson.build.patch @@ -0,0 +1,11 @@ +--- src/intel/vulkan/meson.build 2022-07-15 18:42:47.000000000 +0100 ++++ src/intel/vulkan/meson.build 2022-11-30 18:21:07.247725902 +0000 +@@ -95,7 +95,7 @@ + dependencies : [ + dep_libdrm, dep_valgrind, idep_nir_headers, idep_genxml, + idep_vulkan_util_headers, idep_vulkan_wsi_headers, +- idep_vulkan_runtime_headers, idep_intel_driver_ds_headers, ++ idep_vulkan_runtime_headers, idep_intel_driver_ds_headers, dep_x11, + ], + ) + endforeach diff --git a/third_party/mesa/mesa.src_loader_meson.build.patch b/third_party/mesa/mesa.src_loader_meson.build.patch new file mode 100644 index 0000000..4eb07da --- /dev/null +++ b/third_party/mesa/mesa.src_loader_meson.build.patch @@ -0,0 +1,11 @@ +--- src/loader/meson.build 2022-07-15 18:42:47.000000000 +0100 ++++ src/loader/meson.build 2022-11-30 17:26:20.047790496 +0000 +@@ -28,7 +28,7 @@ + include_directories : [inc_include, inc_src], + dependencies : [ + dep_libdrm, dep_xcb_dri3, dep_xcb_present, dep_xcb_sync, dep_xshmfence, +- dep_xcb_xfixes, ++ dep_xcb_xfixes, dep_x11_xcb + ], + build_by_default : false, + ) diff --git a/third_party/mesa/mesa.src_vulkan_util_meson.build.patch b/third_party/mesa/mesa.src_vulkan_util_meson.build.patch new file mode 100644 index 0000000..ad9854e --- /dev/null +++ b/third_party/mesa/mesa.src_vulkan_util_meson.build.patch @@ -0,0 +1,12 @@ +--- src/vulkan/util/meson.build 2022-07-15 18:42:47.000000000 +0100 ++++ src/vulkan/util/meson.build 2022-11-30 17:35:23.627779815 +0000 +@@ -105,7 +105,8 @@ + + idep_vulkan_util_headers = declare_dependency( + sources : [vk_dispatch_table[1], vk_enum_to_str[1], vk_extensions[1]], +- include_directories : include_directories('.') ++ include_directories : include_directories('.'), ++ dependencies : [dep_xcb, dep_x11, dep_xlib_xrandr] + ) + + idep_vulkan_util = declare_dependency( diff --git a/third_party/openssl/BUILD.bazel b/third_party/openssl/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/openssl/BUILD.openssl.bazel b/third_party/openssl/BUILD.openssl.bazel new file mode 100644 index 0000000..156aa32 --- /dev/null +++ b/third_party/openssl/BUILD.openssl.bazel @@ -0,0 +1,122 @@ +"""An openssl build file based on a snippet found in the github issue: +https://github.com/bazelbuild/rules_foreign_cc/issues/337 + +Note that the $(PERL) "make variable" (https://docs.bazel.build/versions/main/be/make-variables.html) +is populated by the perl toolchain provided by rules_perl. +""" + +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make", "configure_make_variant") + +# For building openssl for android (requires versionless so files), see https://github.com/KDAB/android_openssl/blob/update/build_ssl.sh + +# Read https://wiki.openssl.org/index.php/Compilation_and_Installation + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +CONFIGURE_OPTIONS = [ + "no-comp", + "no-idea", + "no-weak-ssl-ciphers", + "no-shared", +] + +LIB_NAME = "openssl" + +MAKE_TARGETS = [ + "build_libs", + "install_dev", +] + +# Rather than use this, try using @bazel_tools//src/conditions:windows_msvc +config_setting( + name = "msvc_compiler", + flag_values = { + "@bazel_tools//tools/cpp:compiler": "msvc-cl", + }, + visibility = ["//visibility:public"], +) + +alias( + name = "openssl", + actual = select({ + ":msvc_compiler": "openssl_msvc", + "//conditions:default": "openssl_default", + }), + visibility = ["//visibility:public"], +) + +configure_make_variant( + name = "openssl_msvc", + build_data = [ + "@nasm//:nasm", + ], + configure_command = "Configure", + configure_in_place = True, + configure_options = CONFIGURE_OPTIONS + [ + "VC-WIN64A", + # Unset Microsoft Assembler (MASM) flags set by built-in MSVC toolchain, + # as NASM is unsed to build OpenSSL rather than MASM + "ASFLAGS=\" \"", + ], + configure_prefix = "$$PERL", + copts = [ + # Required so that jom can build in parallel + "-FS", + ], + env = { + # The Zi flag must be set otherwise OpenSSL fails to build due to missing .pdb files + "CFLAGS": "-Zi", + "PATH": "$$(dirname $(execpath @nasm//:nasm)):$$PATH", + "PERL": "$$EXT_BUILD_ROOT$$/$(PERL)", + }, + lib_name = LIB_NAME, + lib_source = ":all_srcs", + out_static_libs = [ + "libssl.lib", + "libcrypto.lib", + ], + targets = MAKE_TARGETS, + # TODO use @jom_//jom--windows-x86_64_toolchain. - probably best to have alias "@jom//:jom_toolchain" + toolchain = "//third_party/jom:jom_toolchain", + #toolchain = "@rules_foreign_cc//toolchains:preinstalled_nmake_toolchain", + toolchains = ["@rules_perl//:current_toolchain"], +) + +configure_make( + name = "openssl_default", + configure_command = "config", + configure_in_place = True, + configure_options = CONFIGURE_OPTIONS, + env = select({ + "@platforms//os:macos": { + "AR": "", + "PERL": "$$EXT_BUILD_ROOT$$/$(PERL)", + }, + "//conditions:default": { + "PERL": "$$EXT_BUILD_ROOT$$/$(PERL)", + }, + }), + lib_name = LIB_NAME, + lib_source = ":all_srcs", + # Note that for Linux builds, libssl must come before libcrypto on the linker command-line. + # As such, libssl must be listed before libcrypto + out_static_libs = [ + "libssl.a", + "libcrypto.a", + ], + targets = MAKE_TARGETS, + toolchains = ["@rules_perl//:current_toolchain"], +) + +filegroup( + name = "gen_dir", + srcs = [":openssl"], + output_group = "gen_dir", + visibility = ["//visibility:public"], +) diff --git a/third_party/python2/BUILD.bazel b/third_party/python2/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/python2/BUILD.python2_linux.bazel b/third_party/python2/BUILD.python2_linux.bazel new file mode 100644 index 0000000..b0704d2 --- /dev/null +++ b/third_party/python2/BUILD.python2_linux.bazel @@ -0,0 +1,54 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") +# load("@rules_python//python:defs.bzl", "py_runtime_pair") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +configure_make( + name = "python2", + configure_options = [ + "CFLAGS='-Dredacted=\"redacted\"'", + "--with-openssl=$EXT_BUILD_DEPS/openssl", + "--with-zlib=$EXT_BUILD_DEPS/zlib", + "--enable-optimizations", + ], + # rules_foreign_cc defaults the install_prefix to "python". This conflicts with the "python" executable that is generated. + install_prefix = "py_install", + lib_source = ":all_srcs", + out_binaries = [ + "python2.7", + ], + out_data_dirs = ["lib"], + # Building these targets rather than the default prevents tests from being run, which take a while + targets = [ + "build_all", + "altinstall", + ], + deps = [ + "@openssl", + "@zlib", + ], +) + +filegroup( + name = "python2_exe", + srcs = [":python2"], + output_group = "python2.7", +) + +# py_runtime( +# name = "py2_runtime", +# files = ["@python2"], +# interpreter = "python2_bin", +# python_version = "PY2", +# ) + +# py_runtime_pair( +# name = "py_runtime_pair", +# py2_runtime = ":py2_runtime", +# py3_runtime = None, +# ) diff --git a/third_party/qt/BUILD.bazel b/third_party/qt/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/qt/BUILD.qt.bazel b/third_party/qt/BUILD.qt.bazel new file mode 100644 index 0000000..e379717 --- /dev/null +++ b/third_party/qt/BUILD.qt.bazel @@ -0,0 +1,362 @@ +# Seems that perl is no longer required to build qt - https://www.qt.io/blog/perl-is-out-of-the-list-of-dependencies + + + +load("@rules_cc//cc:defs.bzl", "cc_import") +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake",) + +package( default_visibility = ["//visibility:public"]) + +# TODO - if i need to use python in my rules_qt repo, register hermetic toolchain in repository rule and like rules_foreign_cc, wrap it in a "register_toolchains" boolean which is true by default + +BINARIES = [ + "androiddeployqt", + "androidtestrunner", + "assistant", + "balsam", + "balsamui", + "canbusutil", + "cmake_automoc_parser", + "designer", + "instancer", + "lconvert", + "linguist", + "lprodump", + "lrelease", + "lrelease-pro", + "lupdate", + "lupdate-pro", + "meshdebug", + "moc", + "pixeltool", + "qdbus", + "qdbuscpp2xml", + "qdbusviewer", + "qdbusxml2cpp", + "qdistancefieldgenerator", + "qhelpgenerator", + "qlalr", + "qmake", + "qmake6", + "qml", + "qmlcachegen", + "qmldom", + "qmleasing", + "qmlformat", + "qmlimportscanner", + "qmllint", + "qmlplugindump", + "qmlpreview", + "qmlprofiler", + "qmlscene", + "qmltestrunner", + "qmltime", + "qmltyperegistrar", + "qsb", + "qscxmlc", + "qtattributionsscanner", + "qtdiag", + "qtdiag6", + "qtpaths", + "qtpaths6", + "qtplugininfo", + "qvkgen", + "rcc", + "repc", + "shadergen", + "tracegen", + "uic", +] + +EXTRA_WIN_BINARIES = [ + "dumpcpp", + "dumpdoc", + "idc", + "testcon", + "windeployqt", +] + +# TODO link with individual libs. May need to have filegroup for each lib which includes the includes. Look ok rules foreign cc issues for linking libs individually +# TODO add QtPdf and QtWebEngine or whatever they are called. Basically run the build again and get new list of libs +LIBS = [ + "Qt63DAnimation", + "Qt63DCore", + "Qt63DExtras", + "Qt63DInput", + "Qt63DLogic", + "Qt63DQuick", + "Qt63DQuickAnimation", + "Qt63DQuickExtras", + "Qt63DQuickInput", + "Qt63DQuickRender", + "Qt63DQuickScene2D", + "Qt63DRender", + "Qt6Bluetooth", + "Qt6Bodymovin", + "Qt6Charts", + "Qt6ChartsQml", + "Qt6Coap", + "Qt6Concurrent", + "Qt6Core", + "Qt6Core5Compat", + "Qt6DataVisualization", + "Qt6DBus", + "Qt6Designer", + "Qt6DesignerComponents", + "Qt6Gui", + "Qt6Help", + "Qt6LabsAnimation", + "Qt6LabsFolderListModel", + "Qt6LabsQmlModels", + "Qt6LabsSettings", + "Qt6LabsSharedImage", + "Qt6LabsWavefrontMesh", + "Qt6Mqtt", + "Qt6Multimedia", + "Qt6MultimediaQuick", + "Qt6MultimediaWidgets", + "Qt6Network", + "Qt6NetworkAuth", + "Qt6Nfc", + "Qt6OpcUa", + "Qt6OpenGL", + "Qt6OpenGLWidgets", + "Qt6Positioning", + "Qt6PositioningQuick", + "Qt6PrintSupport", + "Qt6Qml", + "Qt6QmlCore", + "Qt6QmlLocalStorage", + "Qt6QmlModels", + "Qt6QmlWorkerScript", + "Qt6QmlXmlListModel", + "Qt6Quick", + "Qt6Quick3D", + "Qt6Quick3DAssetImport", + "Qt6Quick3DAssetUtils", + "Qt6Quick3DEffects", + "Qt6Quick3DHelpers", + "Qt6Quick3DIblBaker", + "Qt6Quick3DParticles", + "Qt6Quick3DRuntimeRender", + "Qt6Quick3DUtils", + "Qt6QuickControls2", + "Qt6QuickControls2Impl", + "Qt6QuickDialogs2", + "Qt6QuickDialogs2QuickImpl", + "Qt6QuickDialogs2Utils", + "Qt6QuickLayouts", + "Qt6QuickParticles", + "Qt6QuickShapes", + "Qt6QuickTemplates2", + "Qt6QuickTest", + "Qt6QuickTimeline", + "Qt6QuickWidgets", + "Qt6RemoteObjects", + "Qt6RemoteObjectsQml", + "Qt6Scxml", + "Qt6ScxmlQml", + "Qt6Sensors", + "Qt6SensorsQuick", + "Qt6SerialBus", + "Qt6SerialPort", + "Qt6ShaderTools", + "Qt6Sql", + "Qt6StateMachine", + "Qt6StateMachineQml", + "Qt6Svg", + "Qt6SvgWidgets", + "Qt6Test", + "Qt6UiTools", + "Qt6VirtualKeyboard", + "Qt6WebChannel", + "Qt6WebSockets", + "Qt6WebView", + "Qt6WebViewQuick", + "Qt6Widgets", + "Qt6Xml", +] + +config_setting( + name = "android", + constraint_values = [ + "@platforms//os:android", + "@platforms//cpu:arm", + ], +) + +# Bazel does not distinguish between C and C++ compilers. Therefore, rules_foreign_cc sets the CXX environment variable to the same as CC, causing the build of qt to fail +# This genrule creates a txt file which when "sourced" will set CXX. +# TODO fix indentation of CXX=\\$${CC} below +genrule( + name = "cxx_var", + outs = ["cxx_var.sh"], + cmd = """ + cat > $@ << EOF + COMPILER=$$(basename \\$${CC}) + if [[ \\$${COMPILER} == *gcc ]]; then + CXX=\\$${COMPILER%gcc}g++ + elif [[ \\$${COMPILER} == clang ]]; then + CXX=\\$${COMPILER%clang}clang++ + else + CXX=\\$${CC} + fi + export CXX +EOF + """, +) + +# Paths must be given in Windows style (.e.g C:/ rather than /c) when building on Qt on Windows +genrule( + name = "realpath", + outs = ["realpath.sh"], + cmd = """ + cat > $@ << EOF + if [[ \\$$(uname) == *"NT"* ]]; then + cygpath -m \\$$1 + else + realpath \\$$1 + fi +EOF + """, + executable = True, +) + +[ + alias( + name = tool, + actual = select({ + "@bazel_tools//src/conditions:host_windows": "@winflexbison//:{}_exe".format(tool), + "//conditions:default": "@{}//:{}_exe".format(tool, tool), + }), + ) + for tool in [ + "flex", + "bison", + ] +] + +filegroup( + name = "qt_install_dir", + srcs = [":qt"], + # gen_dir output group is provided by the cmake() rule + output_group = "gen_dir", + visibility = ["//visibility:public"], +) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]) +) + +TOOL_PREFIX = "source $$EXT_BUILD_ROOT$$/$(location :cxx_var) && unset CFLAGS CXXFLAGS ASMFLAGS &&" + +# have to add "link_libraries(stdc++ m)" to top of top level CMakeLists. wrap "if compiler is clang or gcc" around it +cmake( + name = "qt", + # $EXT_BUILD_ROOT/external/cmake-3.22.1-windows-x86_64/bin/cmake.exe -DCMAKE_AR="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/lib.exe" -DCMAKE_CXX_LINK_EXECUTABLE="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/link.exe -o " -DCMAKE_SHARED_LINKER_FLAGS="-nologo -DLL -SUBSYSTEM:CONSOLE -MACHINE:X64 -DEFAULTLIB:msvcrt.lib" -DCMAKE_EXE_LINKER_FLAGS="-nologo -SUBSYSTEM:CONSOLE -MACHINE:X64 -DEFAULTLIB:msvcrt.lib" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_INSTALL_PREFIX="$INSTALLDIR" -DCMAKE_PREFIX_PATH="$EXT_BUILD_DEPS" -DCMAKE_RANLIB="" -DCMAKE_MAKE_PROGRAM=$EXT_BUILD_ROOT/external/ninja_1.10.2_win/ninja.exe -G 'Ninja' $EXT_BUILD_ROOT/external/qt + build_args = ["--parallel 6"], + build_data = [ + ":cxx_var", + "@gperf//:gperf_exe", + "@python2//:python2_exe", + ":flex", + ":bison", + ], + cache_entries = { + # underscore required after "mesa" as the dir generated by meson_with_requirements appends an underscore + "CMAKE_PREFIX_PATH": "$$EXT_BUILD_DEPS$$/llvm/lib/cmake/llvm;$$EXT_BUILD_DEPS$$/mesa;$$EXT_BUILD_DEPS$$/openssl;$$EXT_BUILD_DEPS$$/zlib", + }, + env = { + "PATH": "$$(dirname $$EXT_BUILD_ROOT$$/$(PERL)):$$(dirname $$EXT_BUILD_ROOT$$/$(NODE_PATH)):$$(dirname $$EXT_BUILD_ROOT$$/$(location @python2//:python2_exe)):$$(dirname $$EXT_BUILD_ROOT$$/$(location @gperf//:gperf_exe)):$$(dirname $$EXT_BUILD_ROOT$$/$(location :flex)):$$(dirname $$EXT_BUILD_ROOT$$/$(location :bison)):$$PATH$$", + }, + # Need to remove "-O2" from command line otherwise cmake step fails. As rules_foreign_cc will set CMAKE_BUILD_TYPE to Release, optimisation will be enabled that way + features = [ + # "-default_link_flags", + #"-opt", + #"-dbg", # to prevent debug build of qt + #Use this once my PR in bazel is merged instead of setting flags to blank above + #"-default_compile_flags", + #"-dynamic_link_msvcrt_no_debug + ], + generate_args = ["-GNinja"], + generate_crosstool_file = False, + + + lib_source = ":all_srcs", + out_binaries = BINARIES, + postfix_script = "cp -p $$INSTALLDIR$$/libexec/* $$INSTALLDIR$$/bin", + # The Qt CMake build attempts to archive a file, which fails if the file is a symlink (i.e inside the bazel sandbox where all files are symlinks). As such, this target cannot be sandboxed + tags = ["no-sandbox"], + # TODO remove my patch for qt and have a genrule that makes a sh file that exports CXX=/path/to/dir/of/gcc/g++, same for clang++ + tool_prefix = TOOL_PREFIX, + toolchains = [ + "@rules_perl//:current_toolchain", + "@rules_python//python:current_py_toolchain", + "@nodejs_toolchains//:resolved_toolchain" + ], + deps = [ + # TODO this caused llvm rebuild even after building llvm for mesa. probably because meson_with_requirements transition affects deps. See if i can change it to be an incoming transition, not outgoing + "@llvm", + "@mesa", + "@openssl", + "@zlib" + ] +) + +filegroup( + name = "qt_include_dir", + srcs = [":qt"], + output_group = "include", + visibility = ["//visibility:public"], +) + +filegroup( + name = "qt_gen_dir", + srcs = [":qt"], + output_group = "gen_dir", + visibility = ["//visibility:public"], +) + +[ + filegroup( + name = bin, + srcs = [":qt"], + # Extract individual binaries using output_group set by rules_foreign_cc + output_group = bin, + visibility = ["//visibility:public"], + ) + for bin in BINARIES +] + +# how to get all binaries, including extra windows ones? for linux, the output group would be nonexistent, so that may be ok. +# or have BINARIES and EXTRA_WIN_BINARIES, but how to iterate over extra ones only on windows? for extra ones, could have alias which results in None for non linux + +# The following rules are required to provide Qt libs individually. A cc_library or cc_binary rule that depends on the cmake() rule directly will depend on ALL qt libraries +# If https://github.com/bazelbuild/bazel/issues/4748 were resolved, only a cc_import instance would be required. Until then , the workaround is to create a cc_library with dependency cc_import +[ + ( + genrule( + name = "{}_shared_lib".format(lib), + srcs = [":qt_gen_dir"], + outs = ["lib{}.so.6".format(lib)], + cmd = "cp $(location :qt_gen_dir)/lib/lib{}.so $@".format(lib), + ), + cc_import( + name = "{}_import".format(lib), + shared_library = ":{}_shared_lib".format(lib), + ), + cc_library( + name = "{}".format(lib), + deps = [ + "{}_import".format(lib), + ":qt", + ] + + # Assume that all Qt libs depend on Qt6Core + [ + ":Qt6Core_import", + ] if (lib != "Qt6Core") else [], + ), + ) + for lib in LIBS +] diff --git a/third_party/vcpkg/BUILD.bazel b/third_party/vcpkg/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/vcpkg/BUILD.vcpkg.bazel b/third_party/vcpkg/BUILD.vcpkg.bazel new file mode 100644 index 0000000..36725bd --- /dev/null +++ b/third_party/vcpkg/BUILD.vcpkg.bazel @@ -0,0 +1,4 @@ +exports_files([ + "ports/gperf/CMakeLists.txt", + "ports/gperf/config.h.in", +]) diff --git a/third_party/xorg/BUILD.bazel b/third_party/xorg/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/xorg/BUILD.libXxf86vm.bazel b/third_party/xorg/BUILD.libXxf86vm.bazel new file mode 100644 index 0000000..620dfde --- /dev/null +++ b/third_party/xorg/BUILD.libXxf86vm.bazel @@ -0,0 +1,16 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "libXxf86vm", + lib_source = ":all_srcs", +) diff --git a/third_party/xorg/BUILD.libpthread-stubs.bazel b/third_party/xorg/BUILD.libpthread-stubs.bazel new file mode 100644 index 0000000..da337c2 --- /dev/null +++ b/third_party/xorg/BUILD.libpthread-stubs.bazel @@ -0,0 +1,17 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "libpthread-stubs", + lib_source = ":all_srcs", + out_headers_only = True, +) diff --git a/third_party/xorg/BUILD.libx11.bazel b/third_party/xorg/BUILD.libx11.bazel new file mode 100644 index 0000000..6ab0dfa --- /dev/null +++ b/third_party/xorg/BUILD.libx11.bazel @@ -0,0 +1,29 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "libx11", + env = select({ + "@platforms//os:macos": { + "AR": "", + }, + "//conditions:default": {}, + }), + lib_source = ":all_srcs", + out_headers_only = True, + deps = [ + "@libxau", + "@libxcb", + "@xorgproto", + "@xtrans", + ], +) diff --git a/third_party/xorg/BUILD.libxau.bazel b/third_party/xorg/BUILD.libxau.bazel new file mode 100644 index 0000000..683d512 --- /dev/null +++ b/third_party/xorg/BUILD.libxau.bazel @@ -0,0 +1,26 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "libxau", + env = select({ + "@platforms//os:macos": { + "AR": "", + }, + "//conditions:default": {}, + }), + lib_source = ":all_srcs", + out_headers_only = True, + deps = [ + "@xorgproto", + ], +) diff --git a/third_party/xorg/BUILD.libxcb.bazel b/third_party/xorg/BUILD.libxcb.bazel new file mode 100644 index 0000000..0b28d2c --- /dev/null +++ b/third_party/xorg/BUILD.libxcb.bazel @@ -0,0 +1,31 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +DEPS = [ + "@libxau", + "@xcb-proto", +] + +configure_make( + name = "libxcb", + env = select({ + "@platforms//os:macos": { + "AR": "", + }, + "//conditions:default": {}, + }), + lib_source = ":all_srcs", + deps = select({ + "@platforms//os:macos": DEPS + ["@libpthread-stubs"], + "//conditions:default": DEPS, + }), +) diff --git a/third_party/xorg/BUILD.libxdmcp.bazel b/third_party/xorg/BUILD.libxdmcp.bazel new file mode 100644 index 0000000..f662770 --- /dev/null +++ b/third_party/xorg/BUILD.libxdmcp.bazel @@ -0,0 +1,20 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "libxdmcp", + lib_source = ":all_srcs", + out_headers_only = True, + deps = [ + "@xorgproto", + ], +) diff --git a/third_party/xorg/BUILD.libxext.bazel b/third_party/xorg/BUILD.libxext.bazel new file mode 100644 index 0000000..bd511f0 --- /dev/null +++ b/third_party/xorg/BUILD.libxext.bazel @@ -0,0 +1,27 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "libxext", + env = select({ + "@platforms//os:macos": { + "AR": "", + }, + "//conditions:default": {}, + }), + lib_source = ":all_srcs", + out_headers_only = True, + deps = [ + "@libx11", + "@xorgproto", + ], +) diff --git a/third_party/xorg/BUILD.libxfixes.bazel b/third_party/xorg/BUILD.libxfixes.bazel new file mode 100644 index 0000000..67da083 --- /dev/null +++ b/third_party/xorg/BUILD.libxfixes.bazel @@ -0,0 +1,29 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "libxfixes", + env = select({ + "@platforms//os:macos": { + "AR": "", + }, + "//conditions:default": {}, + }), + lib_source = ":all_srcs", + out_static_libs = [ + "libXfixes.a", + ], + deps = [ + "@libx11", + "@xorgproto", + ], +) diff --git a/third_party/xorg/BUILD.libxrandr.bazel b/third_party/xorg/BUILD.libxrandr.bazel new file mode 100644 index 0000000..0c6b49e --- /dev/null +++ b/third_party/xorg/BUILD.libxrandr.bazel @@ -0,0 +1,23 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "libxrandr", + lib_source = ":all_srcs", + out_headers_only = True, + deps = [ + "@libx11", + "@libxext", + "@libxrender", + "@renderproto", + ], +) diff --git a/third_party/xorg/BUILD.libxrender.bazel b/third_party/xorg/BUILD.libxrender.bazel new file mode 100644 index 0000000..aa0e3ef --- /dev/null +++ b/third_party/xorg/BUILD.libxrender.bazel @@ -0,0 +1,21 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "libxrender", + lib_source = ":all_srcs", + out_headers_only = True, + deps = [ + "@libx11", + "@renderproto", + ], +) diff --git a/third_party/xorg/BUILD.libxshmfence.bazel b/third_party/xorg/BUILD.libxshmfence.bazel new file mode 100644 index 0000000..0407568 --- /dev/null +++ b/third_party/xorg/BUILD.libxshmfence.bazel @@ -0,0 +1,19 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "libxshmfence", + lib_source = ":all_srcs", + deps = [ + "@xorgproto", + ], +) diff --git a/third_party/xorg/BUILD.renderproto.bazel b/third_party/xorg/BUILD.renderproto.bazel new file mode 100644 index 0000000..6f3961d --- /dev/null +++ b/third_party/xorg/BUILD.renderproto.bazel @@ -0,0 +1,17 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "renderproto", + lib_source = ":all_srcs", + out_headers_only = True, +) diff --git a/third_party/xorg/BUILD.xcb-proto.bazel b/third_party/xorg/BUILD.xcb-proto.bazel new file mode 100644 index 0000000..b7e2a21 --- /dev/null +++ b/third_party/xorg/BUILD.xcb-proto.bazel @@ -0,0 +1,19 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "xcb-proto", + lib_source = ":all_srcs", + # Dependents of xcb-proto require this lib dir to be present in the bazel sandbox + out_data_dirs = ["lib"], + out_headers_only = True, +) diff --git a/third_party/xorg/BUILD.xorgproto.bazel b/third_party/xorg/BUILD.xorgproto.bazel new file mode 100644 index 0000000..d38f46f --- /dev/null +++ b/third_party/xorg/BUILD.xorgproto.bazel @@ -0,0 +1,17 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "xorgproto", + lib_source = ":all_srcs", + out_headers_only = True, +) diff --git a/third_party/xorg/BUILD.xtrans.bazel b/third_party/xorg/BUILD.xtrans.bazel new file mode 100644 index 0000000..9a38471 --- /dev/null +++ b/third_party/xorg/BUILD.xtrans.bazel @@ -0,0 +1,17 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob( + include = ["**"], + exclude = ["*.bazel"], + ), +) + +configure_make( + name = "xtrans", + lib_source = ":all_srcs", + out_headers_only = True, +) diff --git a/third_party/xorg/repositories.bzl b/third_party/xorg/repositories.bzl new file mode 100644 index 0000000..c34bf59 --- /dev/null +++ b/third_party/xorg/repositories.bzl @@ -0,0 +1,140 @@ +""" xorg repositories """ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +# buildifier: disable=function-docstring +def xorg_repositories(): + maybe( + http_archive, + name = "libxcb", + build_file = Label("//third_party/xorg:BUILD.libxcb.bazel"), + sha256 = "cc38744f817cf6814c847e2df37fcb8997357d72fa4bcbc228ae0fe47219a059", + strip_prefix = "libxcb-1.15", + url = "https://xcb.freedesktop.org/dist/libxcb-1.15.tar.xz", + ) + + maybe( + http_archive, + name = "xcb-proto", + build_file = Label("//third_party/xorg:BUILD.xcb-proto.bazel"), + sha256 = "d34c3b264e8365d16fa9db49179cfa3e9952baaf9275badda0f413966b65955f", + strip_prefix = "xcb-proto-1.15", + url = "https://xcb.freedesktop.org/dist/xcb-proto-1.15.tar.xz", + ) + + maybe( + http_archive, + name = "libxshmfence", + build_file = Label("//third_party/xorg:BUILD.libxshmfence.bazel"), + sha256 = "7eb3d46ad91bab444f121d475b11b39273142d090f7e9ac43e6a87f4ff5f902c", + strip_prefix = "libxshmfence-1.3", + url = "https://www.x.org/releases/individual/lib/libxshmfence-1.3.tar.gz", + ) + + maybe( + http_archive, + name = "libxau", + build_file = Label("//third_party/xorg:BUILD.libxau.bazel"), + sha256 = "8be6f292334d2f87e5b919c001e149a9fdc27005d6b3e053862ac6ebbf1a0c0a", + strip_prefix = "libXau-1.0.10", + url = "https://www.x.org/pub/individual/lib/libXau-1.0.10.tar.xz", + ) + + maybe( + http_archive, + name = "xorgproto", + build_file = Label("//third_party/xorg:BUILD.xorgproto.bazel"), + sha256 = "5d13dbf2be08f95323985de53352c4f352713860457b95ccaf894a647ac06b9e", + strip_prefix = "xorgproto-2022.2", + url = "https://xorg.freedesktop.org/archive/individual/proto/xorgproto-2022.2.tar.xz", + ) + + maybe( + http_archive, + name = "libxdmcp", + build_file = Label("//third_party/xorg:BUILD.libxdmcp.bazel"), + sha256 = "2dce5cc317f8f0b484ec347d87d81d552cdbebb178bd13c5d8193b6b7cd6ad00", + strip_prefix = "libXdmcp-1.1.4", + url = "https://www.x.org/pub/individual/lib/libXdmcp-1.1.4.tar.xz", + ) + + maybe( + http_archive, + name = "libx11", + build_file = Label("//third_party/xorg:BUILD.libx11.bazel"), + sha256 = "081bf42ebab023aa92cfdb20c7af8c5ae13d13e88a5e22f90f4453ef80bbdde4", + strip_prefix = "libX11-1.8", + url = "https://www.x.org/archive/individual/lib/libX11-1.8.tar.xz", + ) + + maybe( + http_archive, + name = "libxrandr", + build_file = Label("//third_party/xorg:BUILD.libxrandr.bazel"), + sha256 = "897639014a78e1497704d669c5dd5682d721931a4452c89a7ba62676064eb428", + strip_prefix = "libXrandr-1.5.3", + url = "https://www.x.org/archive/individual/lib/libXrandr-1.5.3.tar.xz", + ) + + maybe( + http_archive, + name = "libxext", + build_file = Label("//third_party/xorg:BUILD.libxext.bazel"), + sha256 = "db14c0c895c57ea33a8559de8cb2b93dc76c42ea4a39e294d175938a133d7bca", + strip_prefix = "libXext-1.3.5", + url = "https://www.x.org/archive/individual/lib/libXext-1.3.5.tar.xz", + ) + + maybe( + http_archive, + name = "libxrender", + build_file = Label("//third_party/xorg:BUILD.libxrender.bazel"), + sha256 = "bc53759a3a83d1ff702fb59641b3d2f7c56e05051fa0cfa93501166fa782dc24", + strip_prefix = "libXrender-0.9.11", + url = "https://www.x.org/archive//individual/lib/libXrender-0.9.11.tar.xz", + ) + + maybe( + http_archive, + name = "renderproto", + build_file = Label("//third_party/xorg:BUILD.renderproto.bazel"), + sha256 = "a0a4be3cad9381ae28279ba5582e679491fc2bec9aab8a65993108bf8dbce5fe", + strip_prefix = "renderproto-0.11.1", + url = "https://www.x.org/releases/individual/proto/renderproto-0.11.1.tar.gz", + ) + + maybe( + http_archive, + name = "xtrans", + build_file = Label("//third_party/xorg:BUILD.xtrans.bazel"), + sha256 = "48ed850ce772fef1b44ca23639b0a57e38884045ed2cbb18ab137ef33ec713f9", + strip_prefix = "xtrans-1.4.0", + url = "https://www.x.org/archive/individual/lib/xtrans-1.4.0.tar.gz", + ) + + maybe( + http_archive, + name = "libpthread-stubs", + build_file = Label("//third_party/xorg:BUILD.libpthread-stubs.bazel"), + sha256 = "f8f7ca635fa54bcaef372fd5fd9028f394992a743d73453088fcadc1dbf3a704", + strip_prefix = "libpthread-stubs-0.1", + url = "https://www.x.org/archive//individual/lib/libpthread-stubs-0.1.tar.gz", + ) + + maybe( + http_archive, + name = "libxfixes", + build_file = Label("//third_party/xorg:BUILD.libxfixes.bazel"), + sha256 = "82045da5625350838390c9440598b90d69c882c324ca92f73af9f0e992cb57c7", + strip_prefix = "libXfixes-6.0.0", + url = "https://www.x.org/archive//individual/lib/libXfixes-6.0.0.tar.gz", + ) + + maybe( + http_archive, + name = "libXxf86vm", + build_file = Label("//third_party/xorg:BUILD.libXxf86vm.bazel"), + sha256 = "5108553c378a25688dcb57dca383664c36e293d60b1505815f67980ba9318a99", + strip_prefix = "libXxf86vm-1.1.4", + url = "https://www.x.org/releases/individual/lib/libXxf86vm-1.1.4.tar.gz", + ) diff --git a/third_party/zlib/BUILD.bazel b/third_party/zlib/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/third_party/zlib/BUILD.zlib.bazel b/third_party/zlib/BUILD.zlib.bazel new file mode 100644 index 0000000..40df76f --- /dev/null +++ b/third_party/zlib/BUILD.zlib.bazel @@ -0,0 +1,62 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +# For building on windows with "-c dbg", output is zlibstaticd.lib rather than zlibstatic.lib +# To handle this, use config setting like below +#config_setting( +# name = "debug_build", +# values = { +# "compilation_mode": "dbg", +# }, +#) +# +# then use "select", like + +# configure_make( +# name = "zlib", +# env = {"CFLAGS": "-fPIC"}, +# configure_options = ["--static"], +# lib_source = ":all", +# out_static_libs = select({ +# ":debug_build": "zlibstaticd.lib", +# "//conditions:default": "zlibstatic.lib" +# }), +# ) + +# may need to AND or OR conditions to say "windows + debug - zlibstaticd.lib" - https://docs.bazel.build/versions/main/configurable-attributes.html#and-chaining + +# configure_make( +# name = "zlib", +# configure_options = ["--static"], +# env = {"CFLAGS": "-fPIC"}, +# lib_source = ":all", +# out_static_libs = [ +# "libz.a", +# ], +# ) + +# perhaps have features=["-dbg"] to ensure it is never build for debug +cmake( + name = "zlib", + cache_entries = select({ + # Set to Linux rather than Android to prevent CMake from trying to automatically detect parameters for an Android build, which are already provided by the Android bazel toolchain + # also see https://github.com/bazelbuild/rules_foreign_cc/issues/289#issuecomment-1201314236 + "@platforms//os:android": {"CMAKE_SYSTEM_NAME": "Linux"}, + "//conditions:default": {}, + }), + generate_args = select({ + "@platforms//os:windows": ["-GNinja"], + "//conditions:default": [], + }), + lib_source = ":all_srcs", + out_static_libs = select({ + "@platforms//os:windows": ["zlibstatic.lib"], + "//conditions:default": ["libz.a"], + }), +)