Skip to content

Commit

Permalink
third_party: Add RE2 build support
Browse files Browse the repository at this point in the history
This CL adds the files needed to build RE2. These files were generated
by `//pw_build/py/pw_build/generate_3p_gn.py`.

Change-Id: I9dd2691bdbb593fb74922bdeae59eb04454dc472
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/135958
Reviewed-by: Rob Mohr <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Commit-Queue: Aaron Green <[email protected]>
Reviewed-by: Taylor Cramer <[email protected]>
  • Loading branch information
nopsledder authored and CQ Bot Account committed May 1, 2023
1 parent 1875778 commit 292b3a6
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 1 deletion.
1 change: 1 addition & 0 deletions pw_fuzzer/fuzzer.gni
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import("//build_overrides/pigweed.gni")

import("$dir_pw_build/error.gni")
import("$dir_pw_third_party/abseil-cpp/abseil-cpp.gni")
import("$dir_pw_third_party/re2/re2.gni")
import("$dir_pw_toolchain/host_clang/toolchains.gni")
import("$dir_pw_unit_test/test.gni")

Expand Down
1 change: 1 addition & 0 deletions pw_package/py/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pw_python_package("py") {
"pw_package/packages/nanopb.py",
"pw_package/packages/pico_sdk.py",
"pw_package/packages/protobuf.py",
"pw_package/packages/re2.py",
"pw_package/packages/smartfusion_mss.py",
"pw_package/packages/stm32cube.py",
"pw_package/pigweed_packages.py",
Expand Down
46 changes: 46 additions & 0 deletions pw_package/py/pw_package/packages/re2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2023 The Pigweed Authors
#
# 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
#
# https://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.
"""Install and check status of RE2."""

import pathlib
from typing import Sequence

import pw_package.git_repo
import pw_package.package_manager


class Re2(pw_package.git_repo.GitRepo):
"""Install and check status of RE2."""

def __init__(self, *args, **kwargs):
super().__init__(
*args,
name='re2',
url=(
'https://pigweed.googlesource.com/'
'third_party/github/google/re2'
),
commit='11073deb73b3d01018308863c0bcdfd0d51d3e70',
**kwargs,
)

def info(self, path: pathlib.Path) -> Sequence[str]:
return (
f'{self.name} installed in: {path}',
"Enable by running 'gn args out' and adding this line:",
f' dir_pw_third_party_re2 = "{path}"',
)


pw_package.package_manager.register(Re2)
1 change: 1 addition & 0 deletions pw_package/py/pw_package/pigweed_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from pw_package.packages import nanopb
from pw_package.packages import pico_sdk
from pw_package.packages import protobuf
from pw_package.packages import re2
from pw_package.packages import smartfusion_mss
from pw_package.packages import stm32cube

Expand Down
5 changes: 4 additions & 1 deletion pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,14 @@ def gn_arm_build(ctx: PresubmitContext):
gn_fuzz_build = build.GnGenNinja(
name='gn_fuzz_build',
path_filter=_BUILD_FILE_FILTER,
packages=('abseil-cpp',),
packages=('abseil-cpp', 're2'),
gn_args={
'dir_pw_third_party_abseil_cpp': lambda ctx: '"{}"'.format(
ctx.package_root / 'abseil-cpp'
),
'dir_pw_third_party_re2': lambda ctx: '"{}"'.format(
ctx.package_root / 're2'
),
},
ninja_targets=('host_clang_fuzz',),
)
Expand Down
87 changes: 87 additions & 0 deletions third_party/re2/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright 2023 The Pigweed Authors
#
# 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
#
# https://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.

# DO NOT MANUALLY EDIT!
# This file was automatically generated by pw_build/gn_writer.py

import("//build_overrides/pigweed.gni")

import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_third_party/re2/re2.gni")

config("re2_public_config1") {
include_dirs = [ "$dir_pw_third_party_re2" ]
}

# Generated from //:re2
pw_source_set("re2") {
public = [
"$dir_pw_third_party_re2/re2/filtered_re2.h",
"$dir_pw_third_party_re2/re2/re2.h",
"$dir_pw_third_party_re2/re2/set.h",
"$dir_pw_third_party_re2/re2/stringpiece.h",
]
sources = [
"$dir_pw_third_party_re2/re2/bitmap256.cc",
"$dir_pw_third_party_re2/re2/bitmap256.h",
"$dir_pw_third_party_re2/re2/bitstate.cc",
"$dir_pw_third_party_re2/re2/compile.cc",
"$dir_pw_third_party_re2/re2/dfa.cc",
"$dir_pw_third_party_re2/re2/filtered_re2.cc",
"$dir_pw_third_party_re2/re2/mimics_pcre.cc",
"$dir_pw_third_party_re2/re2/nfa.cc",
"$dir_pw_third_party_re2/re2/onepass.cc",
"$dir_pw_third_party_re2/re2/parse.cc",
"$dir_pw_third_party_re2/re2/perl_groups.cc",
"$dir_pw_third_party_re2/re2/pod_array.h",
"$dir_pw_third_party_re2/re2/prefilter.cc",
"$dir_pw_third_party_re2/re2/prefilter.h",
"$dir_pw_third_party_re2/re2/prefilter_tree.cc",
"$dir_pw_third_party_re2/re2/prefilter_tree.h",
"$dir_pw_third_party_re2/re2/prog.cc",
"$dir_pw_third_party_re2/re2/prog.h",
"$dir_pw_third_party_re2/re2/re2.cc",
"$dir_pw_third_party_re2/re2/regexp.cc",
"$dir_pw_third_party_re2/re2/regexp.h",
"$dir_pw_third_party_re2/re2/set.cc",
"$dir_pw_third_party_re2/re2/simplify.cc",
"$dir_pw_third_party_re2/re2/sparse_array.h",
"$dir_pw_third_party_re2/re2/sparse_set.h",
"$dir_pw_third_party_re2/re2/stringpiece.cc",
"$dir_pw_third_party_re2/re2/tostring.cc",
"$dir_pw_third_party_re2/re2/unicode_casefold.cc",
"$dir_pw_third_party_re2/re2/unicode_casefold.h",
"$dir_pw_third_party_re2/re2/unicode_groups.cc",
"$dir_pw_third_party_re2/re2/unicode_groups.h",
"$dir_pw_third_party_re2/re2/walker-inl.h",
"$dir_pw_third_party_re2/util/logging.h",
"$dir_pw_third_party_re2/util/mix.h",
"$dir_pw_third_party_re2/util/mutex.h",
"$dir_pw_third_party_re2/util/rune.cc",
"$dir_pw_third_party_re2/util/strutil.cc",
"$dir_pw_third_party_re2/util/strutil.h",
"$dir_pw_third_party_re2/util/utf.h",
"$dir_pw_third_party_re2/util/util.h",
]
cflags = [ "-pthread" ]
ldflags = [ "-pthread" ]
public_configs = [ ":re2_public_config1" ]
configs = [ "configs:internal_disabled_warnings" ]
remove_configs = [ "$dir_pw_fuzzer:instrumentation" ]
}

pw_doc_group("docs") {
sources = [ "docs.rst" ]
}
1 change: 1 addition & 0 deletions third_party/re2/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[email protected]
34 changes: 34 additions & 0 deletions third_party/re2/configs/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2023 The Pigweed Authors
#
# 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
#
# https://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.

# Targets that include RE2 headers need to include this config.
config("disabled_warnings") {
cflags = [
"-Wno-dtor-name",
"-Wno-gnu-anonymous-struct",
"-Wno-nested-anon-types",
]
}

# This config should only be used to build the RE2 library itself.
config("internal_disabled_warnings") {
cflags = [
"-Wno-c99-extensions",
"-Wno-cast-qual",
"-Wno-shadow",
"-Wno-switch-enum",
"-Wno-unused-parameter",
]
configs = [ ":disabled_warnings" ]
}
53 changes: 53 additions & 0 deletions third_party/re2/docs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
.. _module-pw_third_party_re2:

===
RE2
===
The ``$dir_pw_third_party/re2/`` module provides build files to allow
optionally including upstream RE2.

------------------
Using upstream RE2
------------------
If you want to use RE2, you must do the following:

Submodule
=========
Add RE2 to your workspace with the following command.

.. code-block:: sh
git submodule add https://github.com/google/re2.git \
third_party/re2/src
GN
==
* Set the GN var ``dir_pw_third_party_re2`` to the location of the
RE2 source.

If you used the command above, this will be
``//third_party/re2/src``

This can be set in your args.gn or .gn file like:
``dir_pw_third_party_re2 = "//third_party/re2/src"``

Updating
========
The GN build files are generated from the third-party Bazel build files using
$dir_pw_build/py/pw_build/generate_3p_gn.py.

The script uses data taken from ``$dir_pw_third_party/re2/repo.json``.

The script should be re-run whenever the submodule is updated or the JSON file
is modified. Specify the location of the Bazel repository can be specified using
the ``-w`` option, e.g.

.. code-block:: sh
python pw_build/py/pw_build/generate_3p_gn.py \
-w third_party/re2/src
Version
=======
The update script was last run for revision:
11073deb73b3d01018308863c0bcdfd0d51d3e70
23 changes: 23 additions & 0 deletions third_party/re2/re2.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 The Pigweed Authors
#
# 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
#
# https://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.

# DO NOT MANUALLY EDIT!
# This file was automatically generated by pw_build/gn_writer.py

declare_args() {
# If compiling tests with RE2, this variable is set to the path to the RE2
# installation. When set, a pw_source_set for the RE2 library is created at
# "$dir_pw_third_party/re2".
dir_pw_third_party_re2 = ""
}
5 changes: 5 additions & 0 deletions third_party/re2/repo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "RE2",
"add": [ "$dir_pw_third_party/re2/configs:internal_disabled_warnings" ],
"remove": [ "$dir_pw_fuzzer:instrumentation" ]
}

0 comments on commit 292b3a6

Please sign in to comment.