Skip to content
Open
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
21 changes: 20 additions & 1 deletion bzl/valdi/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "int_flag", "string_flag")
load("@valdi//bzl/conditions:selects.bzl", "selects")
load("@valdi//bzl/valdi:valdi_toolchain.bzl", "valdi_toolchain")
load("@valdi//bzl/valdi:valdi_toolchain_binary.bzl", "valdi_toolchain_binary")
Expand All @@ -13,6 +13,7 @@ exports_files([
"empty.swift",
"empty.kt",
"empty.js",
"empty_android_manifest.xml",
"Empty.bundle/Info.plist",
"Info.plist",
"package.json.tmpl",
Expand Down Expand Up @@ -49,6 +50,24 @@ string_flag(
visibility = ["//visibility:public"],
)

int_flag(
name = "native_api_min_version",
build_setting_default = -1,
visibility = ["//visibility:public"],
)

filegroup(
name = "empty_api_version_file",
srcs = [],
visibility = ["//visibility:public"],
)

label_flag(
name = "api_version_file",
build_setting_default = ":empty_api_version_file",
visibility = ["//visibility:public"],
)

string_flag(
name = "assets_mode",
build_setting_default = "bundle",
Expand Down
1 change: 1 addition & 0 deletions bzl/valdi/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ BUILD_DIR = ".valdi_build/compile"
TYPESCRIPT_OUTPUT_DIR = paths.join(BUILD_DIR, "typescript/output")
TYPESCRIPT_GENERATED_TS_DIR = paths.join(BUILD_DIR, "generated_ts")
TYPESCRIPT_DUMPED_SYMBOLS_DIR = paths.join(BUILD_DIR, "typescript/dumped_symbols")
COMPILATION_METADATA_FILENAME = "compilation-metadata.json"

def base_relative_dir(platform, output_target, relative_dir):
"""Helper function for constructing paths relative to the _BASE_DIR.
Expand Down
2 changes: 2 additions & 0 deletions bzl/valdi/empty_android_manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.snap.valdi.empty" />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semgrep identified an issue in your code:
This literal might contain a Snapchat internal reference that should not be committed to open-source repositories.

Fix: Please replace / remove the string to avoid committing it to open-source repositories.

To resolve this comment:

✨ Commit fix suggestion
  1. Replace the internal package name in the manifest with a neutral open-source identifier that does not include .snap, for example change package="com.snap.valdi.empty" to something like package="com.example.valdi.empty".
  2. Keep the new package value consistent with the module’s intended public namespace so Android tooling still treats it as the app/package identifier.
  3. Alternatively, if this manifest is only a placeholder or test fixture, remove the package attribute entirely when it is not required by the file’s purpose.
💬 Ignore this finding

Reply with Semgrep commands to ignore this finding.

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by internal-sensitive-strings.

You can view more details about this finding in the Semgrep AppSec Platform.

8 changes: 7 additions & 1 deletion bzl/valdi/valdi_android_application.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load(
"generate_valdi_android_application_icons",
_valdi_android_application_icons = "valdi_android_application_icons",
)
load("//bzl/valdi:valdi_android_resource_deps.bzl", "valdi_android_resource_deps")
load("//bzl/valdi/source_set:utils.bzl", "source_set_select")

def valdi_android_application_icons(src, round_src = None):
Expand Down Expand Up @@ -34,10 +35,15 @@ def valdi_android_application(
round_icon_name = None,
activity_theme_name = None,
deps = [],
resources = [],
native_deps = []):
src_target = "{}_src".format(name)
src_activity_target = "{}_activitygen".format(name)
aar_target = "{}_aar".format(name)
resource_deps = valdi_android_resource_deps(
name = "{}_resources".format(name),
resources = resources,
)

generated_app_icons = generate_valdi_android_application_icons(
name,
Expand Down Expand Up @@ -123,5 +129,5 @@ def valdi_android_application(
deps = [
":{}".format(src_target),
":{}_import".format(aar_target),
],
] + resource_deps,
)
19 changes: 19 additions & 0 deletions bzl/valdi/valdi_android_resource_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Helpers for packaging cross-platform Valdi resources."""

load("@rules_android//rules:rules.bzl", "android_library")

def valdi_android_resource_deps(name, resources):
"""Creates an Android asset dependency for cross-platform resources."""
if not resources:
return []

android_library(
name = name,
assets = resources,
# Keep these resources independent of the application's assets_dir.
# The empty root packages source resources relative to their owning
# Bazel package and generated resources relative to their output root.
assets_dir = "",
manifest = "@valdi//bzl/valdi:empty_android_manifest.xml",
)
return [":{}".format(name)]
5 changes: 5 additions & 0 deletions bzl/valdi/valdi_application.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ def valdi_application(
desktop_window_width = 600,
desktop_window_height = 800,
desktop_window_resizable = True,
resources = [],
version = None,
deps = []):
resources = resources + [Label("//bzl/valdi:api_version_file")]
resolved_ios_bundle_id = ios_bundle_id if ios_bundle_id else "com.snap.valdi.{}".format(name)
resolved_android_package = android_package if android_package else "com.snap.valdi.{}".format(name)
resolved_app_icons = icons if icons != None else app_icons
Expand Down Expand Up @@ -91,6 +93,7 @@ def valdi_application(
minimum_os_version = ios_minimum_os_version,
provisioning_profile = ios_provisioning_profile,
app_icons = ios_app_icons,
resources = resources,
version = version,
deps = get_suffixed_deps(deps, "_objc"),
)
Expand All @@ -109,6 +112,7 @@ def valdi_application(
round_icon_name = android_round_app_icon_name,
activity_theme_name = android_activity_theme_name,
deps = get_suffixed_deps(deps, "_kt"),
resources = resources,
native_deps = get_suffixed_deps(deps, "_native"),
)

Expand All @@ -121,6 +125,7 @@ def valdi_application(
window_height = desktop_window_height,
window_resizable = desktop_window_resizable,
app_icons = macos_app_icons,
resources = resources,
deps = get_suffixed_deps(deps, "_native"),
)

Expand Down
31 changes: 31 additions & 0 deletions bzl/valdi/valdi_compilation_metadata.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Collects compilation metadata from a transitive graph of Valdi modules."""

load(":common.bzl", "COMPILATION_METADATA_FILENAME")
load(":valdi_compiled.bzl", "ValdiModuleInfo")

def _valdi_compilation_metadata_impl(ctx):
intermediates = depset(
transitive = [
dep[ValdiModuleInfo].intermediates
for dep in ctx.attr.deps
],
)
metadata = [
file
for file in intermediates.to_list()
if file.basename == COMPILATION_METADATA_FILENAME
]
return [DefaultInfo(files = depset(metadata))]

valdi_compilation_metadata = rule(
implementation = _valdi_compilation_metadata_impl,
doc = "Returns compilation-metadata.json artifacts for the transitive closure of Valdi module dependencies.",
attrs = {
"deps": attr.label_list(
mandatory = True,
cfg = "exec",
providers = [ValdiModuleInfo],
doc = "Valdi modules whose transitive compilation metadata should be collected.",
),
},
)
11 changes: 9 additions & 2 deletions bzl/valdi/valdi_compiled.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ load(
"common.bzl",
"ANDROID_RESOURCE_VARIANT_DIRECTORIES",
"BUILD_DIR",
"COMPILATION_METADATA_FILENAME",
"IOS_API_NAME_SUFFIX",
"IOS_DEFAULT_MODULE_NAME_PREFIX",
"IOS_OUTPUT_BASE",
Expand Down Expand Up @@ -374,6 +375,9 @@ valdi_compiled = rule(
allow_single_file = True,
default = "valdi_config.yaml.tpl",
),
"_native_api_min_version": attr.label(
default = "@valdi//bzl/valdi:native_api_min_version",
),
},
)

Expand Down Expand Up @@ -1438,7 +1442,7 @@ def _get_ios_image_resources_paths(module_name, resources_basenames):
return [debug_images, release_images]

def _get_dumped_compilation_metadata(module_name):
return paths.join(TYPESCRIPT_DUMPED_SYMBOLS_DIR, module_name, "compilation-metadata.json")
return paths.join(TYPESCRIPT_DUMPED_SYMBOLS_DIR, module_name, COMPILATION_METADATA_FILENAME)

def _get_dependency_data_path(module_name):
return base_relative_dir("ios", "metadata", "dependencyData.json")
Expand Down Expand Up @@ -1897,7 +1901,7 @@ def _extract_dts_files(srcs):
return [f for f in srcs if f.basename.endswith(".d.ts")]

def _extract_dumped_compilation_metadata(files):
return [f for f in files if f.basename.endswith("compilation-metadata.json")]
return [f for f in files if f.basename == COMPILATION_METADATA_FILENAME]

def _extract_valdi_module_android(output_target, module_name, outputs):
debug_path, release_path = _get_android_valdi_module_paths(module_name)
Expand Down Expand Up @@ -2319,5 +2323,8 @@ valdi_hotreload = rule(
allow_single_file = True,
default = "valdi_config.yaml.tpl",
),
"_native_api_min_version": attr.label(
default = "@valdi//bzl/valdi:native_api_min_version",
),
},
)
1 change: 1 addition & 0 deletions bzl/valdi/valdi_config.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ node_modules_target: {NODE_MODULES_TARGET}
node_modules_workspace: {NODE_MODULES_WORKSPACE}
external_modules_target: {EXTERNAL_MODULES_TARGET}
external_modules_workspace: {EXTERNAL_MODULES_WORKSPACE}
{NATIVE_API_MIN_VERSION_CONFIG}
13 changes: 11 additions & 2 deletions bzl/valdi/valdi_exported_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("//bzl:expand_template.bzl", "expand_template")
load("//bzl/android:collect_android_assets.bzl", "collect_android_assets")
load("//bzl/valdi:rewrite_hdrs.bzl", "rewrite_hdrs")
load("//bzl/valdi:suffixed_deps.bzl", "get_suffixed_deps")
load("//bzl/valdi:valdi_android_resource_deps.bzl", "valdi_android_resource_deps")
load("//bzl/valdi:valdi_collapse_web_paths.bzl", "collapse_native_paths", "collapse_web_paths", "generate_native_module_map", "generate_register_native_modules")
load("//bzl/valdi:valdi_protodecl_to_js.bzl", "collapse_protodecl_paths", "protodecl_to_js_dir")
load("//bzl/valdi/source_set:utils.bzl", "source_set_select")
Expand Down Expand Up @@ -37,7 +38,8 @@ def valdi_exported_library(
web_package_name = None,
npm_scope = "",
npm_version = "1.0.0",
web_exclude_jsx_global_declaration = False):
web_exclude_jsx_global_declaration = False,
resources = []):
"""Exports Valdi modules as platform-specific libraries (xcframework, aar, npm).

Args:
Expand All @@ -48,9 +50,15 @@ def valdi_exported_library(
Only needed for multi-module exports with cross-module Swift imports.
ValdiCoreSwift is always included automatically.
"""
resources = resources + [Label("//bzl/valdi:api_version_file")]
if not web_package_name:
web_package_name = "{}_npm".format(name)

android_resource_deps = valdi_android_resource_deps(
name = "{}_resources_android".format(name),
resources = resources,
)

ios_public_hdrs_name = "{}_ios_hdrs".format(name)
rewrite_hdrs(
name = ios_public_hdrs_name,
Expand Down Expand Up @@ -113,6 +121,7 @@ done | sed '/^import ValdiCoreSwift$$/d' > $@
apple_xcframework(
name = "{}_ios".format(name),
bundle_name = ios_bundle_name,
data = resources,
deps = xcframework_deps,
infoplists = [
"@valdi//bzl/valdi:Info.plist",
Expand All @@ -135,7 +144,7 @@ done | sed '/^import ValdiCoreSwift$$/d' > $@
public_hdrs = [":{}".format(ios_public_hdrs_name)],
)

java_deps = java_deps + get_suffixed_deps(deps, "_kt")
java_deps = java_deps + get_suffixed_deps(deps, "_kt") + android_resource_deps

collect_android_assets(
name = "{}_android_assets".format(name),
Expand Down
2 changes: 2 additions & 0 deletions bzl/valdi/valdi_ios_application.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def valdi_ios_application(
minimum_os_version = None,
provisioning_profile = None,
app_icons = None,
resources = [],
version = None,
deps = []):
main_target = "{}_maingen".format(name)
Expand Down Expand Up @@ -96,6 +97,7 @@ def valdi_ios_application(
minimum_os_version = minimum_os_version,
provisioning_profile = provisioning_profile,
app_icons = generate_valdi_ios_application_icons(name, app_icons),
resources = resources,
version = resolved_version,
tags = ["valdi_ios_application"],
visibility = ["//visibility:public"],
Expand Down
2 changes: 2 additions & 0 deletions bzl/valdi/valdi_macos_application.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def valdi_macos_application(
window_height,
window_resizable,
app_icons = None,
resources = [],
deps = []):
main_target = "{}_maingen".format(name)
plist_target = "{}_plist".format(name)
Expand Down Expand Up @@ -61,6 +62,7 @@ def valdi_macos_application(
deps = [":{}".format(src_target)],
minimum_os_version = "15.0",
app_icons = generate_valdi_macos_application_icons(name, app_icons),
resources = resources,
tags = ["valdi_macos_application"],
visibility = ["//visibility:public"],
)
3 changes: 3 additions & 0 deletions bzl/valdi/valdi_projectsync.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,8 @@ valdi_projectsync = rule(
allow_single_file = True,
default = "valdi_config.yaml.tpl",
),
"_native_api_min_version": attr.label(
default = "@valdi//bzl/valdi:native_api_min_version",
),
},
)
7 changes: 7 additions & 0 deletions bzl/valdi/valdi_run_compiler.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ load(
"common.bzl",
"NODE_MODULES_BASE",
)
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load(":valdi_toolchain_type.bzl", "VALDI_TOOLCHAIN_TYPE")

# TODO: modify the compiler so that we don't need to pass in the config file and instead can just pass in all of these options as arguments
Expand All @@ -18,6 +19,11 @@ def generate_config(ctx):
companion_path = toolchain.companion.files.to_list()[0].path
minify_config_path = toolchain.minify_config.files.to_list()[0].path
compiler_toolbox_path = toolchain.compiler_toolbox.files.to_list()[0].path
native_api_min_version = ctx.attr._native_api_min_version[BuildSettingInfo].value

native_api_min_version_config = ""
if native_api_min_version >= 0:
native_api_min_version_config = "native_api_min_version: {}".format(native_api_min_version)

ctx.actions.expand_template(
output = out,
Expand All @@ -29,6 +35,7 @@ def generate_config(ctx):
"{MINIFY_CONFIG_PATH}": "$PWD/" + minify_config_path,
"{COMPILER_TOOLBOX_PATH}": "$PWD/" + compiler_toolbox_path,
"{NODE_MODULES_DIR}": NODE_MODULES_BASE,
"{NATIVE_API_MIN_VERSION_CONFIG}": native_api_min_version_config,
},
)
return out
Expand Down
12 changes: 9 additions & 3 deletions bzl/valdi/valdi_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def _valdi_test_impl(ctx):
# Always include standalone module runfiles
valdimodules = _collect_target_runfiles(ctx.attr.target)
valdimodules += _collect_target_runfiles(ctx.attr._valdi_standalone)
module_paths = ["--module_path {}".format(f.short_path) for f in valdimodules]
runtime_files = valdimodules + ctx.files._api_version_file
module_paths = ["--module_path {}".format(f.short_path) for f in runtime_files]

test_script = ctx.actions.declare_file("test_wrapper.sh")
if has_tests:
Expand Down Expand Up @@ -64,10 +65,10 @@ def _valdi_test_impl(ctx):
)

runfiles = ctx.runfiles(
files = [standalone_binary] + valdimodules,
files = [standalone_binary] + runtime_files,
)

return [DefaultInfo(executable = test_script, files = depset([standalone_binary] + valdimodules), runfiles = runfiles)]
return [DefaultInfo(executable = test_script, files = depset([standalone_binary] + runtime_files), runfiles = runfiles)]

valdi_test = rule(
implementation = _valdi_test_impl,
Expand Down Expand Up @@ -99,6 +100,11 @@ valdi_test = rule(
default = Label("@valdi//bzl/valdi:code_coverage_enabled"),
doc = "Enable code coverage collection during tests",
),
"_api_version_file": attr.label(
default = Label("//bzl/valdi:api_version_file"),
allow_files = True,
doc = "Optional repository API-version resource exposed to the standalone test runtime",
),
"_valdi_standalone": attr.label(
default = Label("@valdi//src/valdi_modules/src/valdi/valdi_standalone"),
doc = "The Valdi Standalone target to be added to all Valdi targets",
Expand Down
Loading
Loading