Skip to content

Create rn_codegen BUCK macro #31340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 7 additions & 39 deletions Libraries/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,22 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native")
load(
"//tools/build_defs/oss:rn_codegen_defs.bzl",
"rn_codegen_components",
"rn_codegen_modules",
)
load(
"//tools/build_defs/oss:rn_defs.bzl",
"react_native_root_target",
)

fb_native.genrule(
# The schema name must have the following format: "{name}-codegen-modules-schema"
# Why: Internally, we have build scripts that find all NativeModule schemas in the
# dependencies of an app, and build TurboModuleManager delegates. Those scripts assume
# that all schema targets have the aforementioned naming scheme.
name = "FBReactNativeSpec-codegen-modules-schema",
srcs = glob(
[
"**/*.js",
],
exclude = [
"**/__tests__/**/*",
],
),
cmd = "$(exe {}) $OUT $SRCS".format(react_native_root_target("packages/react-native-codegen:write_to_json")),
out = "schema.json",
labels = [
"codegen_rule",
"react_native_schema_target",
],
"rn_codegen",
)

rn_codegen_modules(
rn_codegen(
name = "FBReactNativeSpec",
android_package_name = "com.facebook.fbreact.specs",
codegen_modules = True,
library_labels = ["supermodule:xplat/default/public.react_native.infra"],
schema_target = ":FBReactNativeSpec-codegen-modules-schema",
native_module_spec_name = "FBReactNativeSpec",
)

rn_codegen_components(
# TODO: Merge this into FBReactNativeSpec
rn_codegen(
name = "FBReactNativeComponentSpec",
codegen_components = True,
library_labels = ["supermodule:xplat/default/public.react_native.infra"],
# Why does FBReactNativeComponentSpec depend on -codegen-modules-schema?
# The module codegen schema also contains components. We cannot change the name
# of the schema target, because internally, we have infra that depends on how
# it's named.
#
# TODO(T83341482): Clean up how OSS NativeModule codegen is declared
schema_target = ":FBReactNativeSpec-codegen-modules-schema",
)
68 changes: 68 additions & 0 deletions tools/build_defs/oss/rn_codegen_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,74 @@ load(
_rn_codegen_components = "rn_codegen_components",
_rn_codegen_modules = "rn_codegen_modules",
)
load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native")
load(
"//tools/build_defs/oss:rn_defs.bzl",
"react_native_root_target",
)

rn_codegen_components = _rn_codegen_components
rn_codegen_modules = _rn_codegen_modules

def rn_codegen(
name,
native_module_spec_name = None,
android_package_name = None,
codegen_components = False,
codegen_modules = False,
library_labels = []):
if (codegen_modules):
error_header = "rn_codegen(name=\"{}\")".format(name)
if not native_module_spec_name:
fail("{}: When codegen_modules = True, native_module_spec_name must be specified.".format(error_header))

if not android_package_name:
fail("{}: When codegen_modules = True, android_package_name must be specified.".format(error_header))

spec_srcs = native.glob(
[
"**/Native*.js",
],
exclude = [
"**/__*__/**",
],
)

module_schema_target = "{}-codegen-modules-schema".format(native_module_spec_name)

fb_native.genrule(
name = module_schema_target,
srcs = spec_srcs,
cmd = "$(exe {}) $OUT $SRCS".format(react_native_root_target("packages/react-native-codegen:write_to_json")),
out = "schema-{}.json".format(native_module_spec_name),
labels = ["codegen_rule", "react_native_schema_target"],
)

rn_codegen_modules(
name = native_module_spec_name,
android_package_name = android_package_name,
schema_target = ":{}".format(module_schema_target),
library_labels = library_labels,
)

if (codegen_components):
fb_native.genrule(
name = "codegen_rn_components_schema_{}".format(name),
srcs = native.glob(
[
"**/*NativeComponent.js",
],
exclude = [
"**/__*__/**",
],
),
cmd = "$(exe {}) $OUT $SRCS".format(react_native_root_target("packages/react-native-codegen:write_to_json")),
out = "schema-{}.json".format(name),
labels = ["codegen_rule"],
)

rn_codegen_components(
name = name,
schema_target = ":codegen_rn_components_schema_{}".format(name),
library_labels = library_labels,
)