diff --git a/ReactAndroid/src/main/java/com/facebook/react/reactperflogger/jni/BUCK b/ReactAndroid/src/main/java/com/facebook/react/reactperflogger/jni/BUCK index 481682cb97c8c3..bd6a96575ac35c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/reactperflogger/jni/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/reactperflogger/jni/BUCK @@ -1,4 +1,4 @@ -load("@fbsource//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_xplat_target", "rn_xplat_cxx_library") +load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_xplat_target", "rn_xplat_cxx_library") rn_xplat_cxx_library( name = "jni", diff --git a/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/BUCK b/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/BUCK index 934dd73ac5d5c7..b0db877eea667d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/BUCK @@ -1,4 +1,4 @@ -load("@fbsource//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_target", "react_native_xplat_target", "rn_xplat_cxx_library") +load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_target", "react_native_xplat_shared_library_target", "react_native_xplat_target", "rn_xplat_cxx_library") rn_xplat_cxx_library( name = "jni", @@ -33,7 +33,7 @@ rn_xplat_cxx_library( ], exported_deps = [ ":callinvokerholder", - "//xplat/jsi:jsi", + react_native_xplat_shared_library_target("jsi:jsi"), react_native_xplat_target("react/nativemodule/core:core"), react_native_target("java/com/facebook/react/reactperflogger/jni:jni"), ], diff --git a/ReactCommon/jsi/BUCK b/ReactCommon/jsi/BUCK index d4d1e6704575d1..ecaba03aa539cd 100644 --- a/ReactCommon/jsi/BUCK +++ b/ReactCommon/jsi/BUCK @@ -1,7 +1,6 @@ # BUILD FILE SYNTAX: SKYLARK -load("@fbsource//tools/build_defs:default_platform_defs.bzl", "APPLE", "IOS", "MACOSX") -load("//tools/build_defs/oss:rn_defs.bzl", "react_native_xplat_dep", "rn_xplat_cxx_library") +load("//tools/build_defs/oss:rn_defs.bzl", "APPLE", "IOS", "MACOSX", "react_native_xplat_dep", "rn_xplat_cxx_library") rn_xplat_cxx_library( name = "jsi", diff --git a/ReactCommon/react/nativemodule/core/BUCK b/ReactCommon/react/nativemodule/core/BUCK index 1bc3b9950df7ee..d5c8981664981a 100644 --- a/ReactCommon/react/nativemodule/core/BUCK +++ b/ReactCommon/react/nativemodule/core/BUCK @@ -1,5 +1,4 @@ -load("@fbsource//tools/build_defs/apple:flag_defs.bzl", "OBJC_ARC_PREPROCESSOR_FLAGS", "get_preprocessor_flags_for_build_mode", "get_static_library_ios_flags") -load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "APPLE", "FBJNI_TARGET", "react_native_target", "react_native_xplat_target", "rn_xplat_cxx_library", "subdir_glob") +load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "APPLE", "FBJNI_TARGET", "OBJC_ARC_PREPROCESSOR_FLAGS", "get_preprocessor_flags_for_build_mode", "get_static_library_ios_flags", "react_native_target", "react_native_xplat_shared_library_target", "react_native_xplat_target", "rn_xplat_cxx_library", "subdir_glob") rn_xplat_cxx_library( name = "core", @@ -83,6 +82,6 @@ rn_xplat_cxx_library( react_native_xplat_target("reactperflogger:reactperflogger"), ], exported_deps = [ - "//xplat/jsi:jsi", + react_native_xplat_shared_library_target("jsi:jsi"), ], ) diff --git a/packages/react-native-codegen/BUCK b/packages/react-native-codegen/BUCK index 008e47e870e0c4..0dccaccecc50f9 100644 --- a/packages/react-native-codegen/BUCK +++ b/packages/react-native-codegen/BUCK @@ -1,7 +1,13 @@ load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native") -load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "APPLE", "IOS", "react_native_target", "rn_android_library", "rn_xplat_cxx_library") +load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "APPLE", "IOS", "IS_OSS_BUILD", "react_native_root_target", "react_native_target", "rn_android_library", "rn_xplat_cxx_library") load("//tools/build_defs/third_party:yarn_defs.bzl", "yarn_workspace") -load(":DEFS.bzl", "rn_codegen_components", "rn_codegen_modules") +load(":DEFS.bzl", "rn_codegen_cli", "rn_codegen_components", "rn_codegen_modules") + +rn_codegen_cli() + +SETUP_ENV_DEPS = [] if IS_OSS_BUILD else [ + "//xplat/js:setup_env", +] fb_native.sh_binary( name = "codegen_rn_modules_tests", @@ -10,8 +16,7 @@ fb_native.sh_binary( resources = [ "src/cli/verify_with_old_codegen.js", "src/cli/verify_with_old_codegen.sh", - "//xplat/js:setup_env", - ], + ] + SETUP_ENV_DEPS, ) fb_native.sh_test( @@ -20,34 +25,6 @@ fb_native.sh_test( visibility = ["PUBLIC"], ) -fb_native.sh_binary( - name = "write_to_json", - main = "src/cli/combine/combine_js_to_schema.sh", - resources = [ - "src/cli/combine/combine-js-to-schema.js", - "src/cli/combine/combine_js_to_schema.sh", - ":yarn-workspace", - "//xplat/js:setup_env", - ], - visibility = ["PUBLIC"], -) - -fb_native.sh_binary( - name = "rn_codegen", - main = "buck_tests/generate-tests.sh", - resources = glob( - [ - "buck_tests/**/*.js", - "src/**/*.js", - ], - ) + [ - "buck_tests/generate-tests.js", - "package.json", - "//xplat/js:setup_env", - ], - visibility = ["PUBLIC"], -) - fb_native.genrule( name = "codegen_tests_schema", srcs = glob( @@ -56,7 +33,7 @@ fb_native.genrule( "**/e2e/__test_fixtures__/modules/Native*.js", ], ), - cmd = "$(exe //xplat/js/react-native-github/packages/react-native-codegen:write_to_json) $OUT $SRCS", + cmd = "$(exe {}) $OUT $SRCS".format(react_native_root_target("packages/react-native-codegen:write_to_json")), out = "schema-codegen_tests.json", ) diff --git a/packages/react-native-codegen/DEFS.bzl b/packages/react-native-codegen/DEFS.bzl index 54eab5012559b0..1df3d9222c33c2 100644 --- a/packages/react-native-codegen/DEFS.bzl +++ b/packages/react-native-codegen/DEFS.bzl @@ -6,6 +6,7 @@ load( "APPLE", "CXX", "IOS", + "IS_OSS_BUILD", "MACOSX", "YOGA_CXX_TARGET", "fb_apple_library", @@ -14,13 +15,96 @@ load( "get_apple_inspector_flags", "get_preprocessor_flags_for_build_mode", "react_native_dep", + "react_native_root_target", "react_native_target", + "react_native_xplat_shared_library_target", "react_native_xplat_target", "react_native_xplat_target_apple", "rn_android_library", "rn_xplat_cxx_library", ) +# Call this in the react-native-codegen/BUCK file +def rn_codegen_cli(): + if not IS_OSS_BUILD: + # FB Internal Setup + fb_native.sh_binary( + name = "write_to_json", + main = "src/cli/combine/combine_js_to_schema.sh", + resources = [ + "src/cli/combine/combine-js-to-schema.js", + "src/cli/combine/combine_js_to_schema.sh", + ":yarn-workspace", + "//xplat/js:setup_env", + ], + visibility = ["PUBLIC"], + ) + + fb_native.sh_binary( + name = "rn_codegen", + main = "buck_tests/generate-tests.sh", + resources = native.glob( + [ + "buck_tests/**/*.js", + "src/**/*.js", + ], + ) + [ + "buck_tests/generate-tests.js", + "package.json", + "//xplat/js:setup_env", + ], + visibility = ["PUBLIC"], + ) + else: + # OSS setup, assumes yarn and node (v12.0.0+) are installed. + fb_native.genrule( + name = "setup_cli", + srcs = native.glob([ + "scripts/**/*", + "src/**/*", + ], exclude = [ + "__tests__/**/*", + ]) + [ + ".babelrc", + ".prettierrc", + "package.json", + ], + out = "build", + bash = r""" + set -euo pipefail + mkdir -p "$OUT" + cp -r "$SRCDIR/" "$OUT/" + cd "$OUT" + yarn install 2> >(grep -v '^warning' 1>&2) + yarn run build + """, + ) + + fb_native.sh_binary( + name = "write_to_json", + main = "scripts/buck-oss/combine_js_to_schema.sh", + resources = [ + ":setup_cli", + ], + visibility = ["PUBLIC"], + ) + + # TODO: This doesn't work yet... + fb_native.sh_binary( + name = "rn_codegen", + main = "buck_tests/generate-tests.sh", + resources = native.glob( + [ + "buck_tests/**/*.js", + "src/**/*.js", + ], + ) + [ + "buck_tests/generate-tests.js", + "package.json", + ], + visibility = ["PUBLIC"], + ) + def rn_codegen_modules( native_module_spec_name, name = "", @@ -36,7 +120,7 @@ def rn_codegen_modules( fb_native.genrule( name = generate_fixtures_rule_name, srcs = native.glob(["src/generators/**/*.js"]), - cmd = "$(exe //xplat/js/react-native-github/packages/react-native-codegen:rn_codegen) $(location {}) {} $OUT {}".format(schema_target, name, native_module_spec_name), + cmd = "$(exe {}) $(location {}) {} $OUT {}".format(react_native_root_target("packages/react-native-codegen:rn_codegen"), schema_target, name, native_module_spec_name), out = "codegenfiles-{}".format(name), labels = ["codegen_rule"], ) @@ -80,8 +164,8 @@ def rn_codegen_modules( labels = ["codegen_rule"], visibility = ["PUBLIC"], deps = [ - "//fbandroid/third-party/java/jsr-305:jsr-305", - "//fbandroid/third-party/java/jsr-330:jsr-330", + react_native_dep("third-party/java/jsr-305:jsr-305"), + react_native_dep("third-party/java/jsr-330:jsr-330"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/common:common"), ], @@ -117,7 +201,7 @@ def rn_codegen_modules( ], deps = [], exported_deps = [ - "//xplat/jsi:jsi", + react_native_xplat_shared_library_target("jsi:jsi"), react_native_xplat_target("react/nativemodule/core:core"), ], platforms = (ANDROID,), @@ -188,7 +272,7 @@ def rn_codegen_components( fb_native.genrule( name = generate_fixtures_rule_name, srcs = native.glob(["src/generators/**/*.js"]), - cmd = "$(exe //xplat/js/react-native-github/packages/react-native-codegen:rn_codegen) $(location {}) {} $OUT {}".format(schema_target, name, name), + cmd = "$(exe {}) $(location {}) {} $OUT {}".format(react_native_root_target("packages/react-native-codegen:rn_codegen"), schema_target, name, name), out = "codegenfiles-{}".format(name), labels = ["codegen_rule"], ) @@ -417,7 +501,7 @@ def rn_codegen_cxx_modules( fb_native.genrule( name = generate_fixtures_rule_name, srcs = native.glob(["src/generators/**/*.js"]), - cmd = "$(exe //xplat/js/react-native-github/packages/react-native-codegen:rn_codegen) $(location {}) {} $OUT {}".format(schema_target, name, name), + cmd = "$(exe {}) $(location {}) {} $OUT {}".format(react_native_root_target("packages/react-native-codegen:rn_codegen"), schema_target, name, name), out = "codegenfiles-{}".format(name), labels = ["codegen_rule"], ) diff --git a/packages/react-native-codegen/scripts/buck-oss/combine_js_to_schema.sh b/packages/react-native-codegen/scripts/buck-oss/combine_js_to_schema.sh new file mode 100755 index 00000000000000..85bfb85a981528 --- /dev/null +++ b/packages/react-native-codegen/scripts/buck-oss/combine_js_to_schema.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# Note: To be invoked by Buck sh_binary() in OSS environment. +# DO NOT USE outside of Buck! + +set -e +set -u + +pushd "$BUCK_DEFAULT_RUNTIME_RESOURCES" >/dev/null +node "build/lib/cli/combine/combine-js-to-schema-cli.js" "$@" +popd >/dev/null diff --git a/tools/build_defs/oss/rn_defs.bzl b/tools/build_defs/oss/rn_defs.bzl index 336d264a864d7b..6be1080867fa78 100644 --- a/tools/build_defs/oss/rn_defs.bzl +++ b/tools/build_defs/oss/rn_defs.bzl @@ -15,12 +15,21 @@ _DEBUG_PREPROCESSOR_FLAGS = [] _APPLE_COMPILER_FLAGS = [] +def get_apple_compiler_flags(): + return _APPLE_COMPILER_FLAGS + def get_preprocessor_flags_for_build_mode(): return _DEBUG_PREPROCESSOR_FLAGS -def get_apple_compiler_flags(): +def get_static_library_ios_flags(): return _APPLE_COMPILER_FLAGS +OBJC_ARC_PREPROCESSOR_FLAGS = [ + "-fobjc-arc", + "-fno-objc-arc-exceptions", + "-Qunused-arguments", +] + IS_OSS_BUILD = True GLOG_DEP = "//ReactAndroid/build/third-party-ndk/glog:glog" @@ -82,6 +91,12 @@ def react_native_xplat_target(path): def react_native_xplat_target_apple(path): return react_native_xplat_target(path) + "Apple" +def react_native_root_target(path): + return "//" + path + +def react_native_xplat_shared_library_target(path): + return react_native_xplat_target(path) + # Example: react_native_tests_target('java/com/facebook/react/modules:modules') def react_native_tests_target(path): return "//ReactAndroid/src/test/" + path diff --git a/tools/build_defs/third_party/yarn_defs.bzl b/tools/build_defs/third_party/yarn_defs.bzl index cd31925f20f763..b98c6e585ffef4 100644 --- a/tools/build_defs/third_party/yarn_defs.bzl +++ b/tools/build_defs/third_party/yarn_defs.bzl @@ -5,4 +5,9 @@ def yarn_workspace(name, srcs = [], transform_ignore = None, visibility = None): # Noop for OSS vs FB build compatibility for now - unused = True + native.genrule( + name = name, + cmd = "echo {} > $OUT".format(name), + out = "{}.txt".format(name), + visibility = visibility, + )