cannot find Scrt1.o: No such file or directory - bazel

I got this error while cross-compile for aarch64. while compile i got error: cannot find Scrt1.o: No such file or directory. but this object is exist.
below is my bazel config.
BUILD
this is BUILD file
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
package(default_visibility = ["//visibility:public"])
filegroup(name = "empty")
filegroup(
name = "all",
srcs = glob([
"**",
]),
)
cc_toolchain_config(name = "s32g_toolchain_config")
cc_toolchain(
name = "s32g_toolchain",
all_files = ":all",
compiler_files = ":all",
dwp_files = ":all",
linker_files = ":all",
objcopy_files = ":all",
strip_files = ":all",
toolchain_config = ":s32g_toolchain_config",
toolchain_identifier = "s32g-toolchain",
)
toolchain_type(name = "toolchain_type")
toolchain(
name = "aarch64_linux_toolchain",
exec_compatible_with = [
"#platforms//os:linux",
"#platforms//cpu:x86_64",
],
target_compatible_with = [
"#platforms//os:linux",
"#platforms//cpu:aarch64",
],
toolchain = ":s32g_toolchain",
toolchain_type = "#bazel_tools//tools/cpp:toolchain_type",
)
cc_toolchain_config.bzl
this is cc_toolchain_config.bzl
load("#bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load(
"#bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
"feature",
"flag_group",
"flag_set",
"tool_path",
)
all_link_actions = [
ACTION_NAMES.cpp_link_executable,
ACTION_NAMES.cpp_link_dynamic_library,
ACTION_NAMES.cpp_link_nodeps_dynamic_library,
]
all_compile_actions = [
ACTION_NAMES.assemble,
ACTION_NAMES.c_compile,
ACTION_NAMES.clif_match,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_codegen,
ACTION_NAMES.cpp_module_compile,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.lto_backend,
ACTION_NAMES.preprocess_assemble,
]
def _impl(ctx):
tool_paths = [
tool_path(
name = "ar",
path = "/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/bin/aarch64-fsl-linux/aarch64-fsl-linux-ar",
),
tool_path(
name = "cpp",
path = "/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/bin/aarch64-fsl-linux/aarch64-fsl-linux-cpp",
),
tool_path(
name = "gcc",
path = "/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/bin/aarch64-fsl-linux/aarch64-fsl-linux-gcc",
),
tool_path(
name = "gcov",
path = "/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/bin/aarch64-fsl-linux/aarch64-fsl-linux-gcov",
),
tool_path(
name = "ld",
path = "/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/bin/aarch64-fsl-linux/aarch64-fsl-linux-ld",
),
tool_path(
name = "nm",
path = "/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/bin/aarch64-fsl-linux/aarch64-fsl-linux-nm",
),
tool_path(
name = "objdump",
path = "/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/bin/aarch64-fsl-linux/aarch64-fsl-linux-objdump",
),
tool_path(
name = "strip",
path = "/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/bin/aarch64-fsl-linux/aarch64-fsl-linux-strip",
),
]
default_compiler_flags = feature(
name = "default_compiler_flags",
enabled = True,
flag_sets = [
flag_set(
actions = all_compile_actions,
flag_groups = [
flag_group(
flags = [
"--sysroot=/opt/xcu-fsl-auto/1.0/sysroots/aarch64-fsl-linux",
"-no-canonical-prefixes",
"-fno-canonical-system-headers",
"-Wno-builtin-macro-redefined",
],
),
],
),
],
)
default_linker_flags = feature(
name = "default_linker_flags",
enabled = True,
flag_sets = [
flag_set(
actions = all_link_actions,
flag_groups = ([
flag_group(
flags = [
"-L/opt/xcu-fsl-auto/1.0/sysroots/aarch64-fsl-linux",
"-L/opt/xcu-fsl-auto/1.0/sysroots/aarch64-fsl-linux/lib",
"-L/opt/xcu-fsl-auto/1.0/sysroots/aarch64-fsl-linux/usr/lib",
"-L/opt/xcu-fsl-auto/1.0/sysroots/aarch64-fsl-linux/usr/lib/aarch64-fsl-linux/10.2.0",
],
),
]),
),
],
)
features = [
default_compiler_flags,
default_linker_flags,
]
return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
cxx_builtin_include_directories = [
"/opt/xcu-fsl-auto/1.0/sysroots/aarch64-fsl-linux/usr/include",
"/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/lib/aarch64-fsl-linux/gcc/aarch64-fsl-linux/10.2.0",
"/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/lib/aarch64-fsl-linux/gcc/aarch64-fsl-linux/10.2.0/include",
],
features = features,
toolchain_identifier = "s32g-toolchain",
host_system_name = "local",
target_system_name = "unknown",
target_cpu = "unknown",
target_libc = "unknown",
compiler = "unknown",
abi_version = "unknown",
abi_libc_version = "unknown",
tool_paths = tool_paths,
)
cc_toolchain_config = rule(
implementation = _impl,
attrs = {},
provides = [CcToolchainConfigInfo],
)
error info
this is the error info.
Use --sandbox_debug to see verbose messages from the sandbox
/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/libexec/aarch64-fsl-linux/gcc/aarch64-fsl-linux/10.2.0/real-ld: cannot find Scrt1.o: No such file or directory
/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/libexec/aarch64-fsl-linux/gcc/aarch64-fsl-linux/10.2.0/real-ld: cannot find crti.o: No such file or directory
/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/libexec/aarch64-fsl-linux/gcc/aarch64-fsl-linux/10.2.0/real-ld: cannot find crtbeginS.o: No such file or directory
according to this link https://github.com/bazelbuild/bazel/issues/3844.
maybe I should declare those objects in cc_toolchain, but I do not understand how to declare them.

I have fix it. just set builtin_sysroot
return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
cxx_builtin_include_directories = [
"/opt/xcu-fsl-auto/1.0/sysroots/aarch64-fsl-linux/usr/include",
"/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/lib/aarch64-fsl-linux/gcc/aarch64-fsl-linux/10.2.0",
"/opt/xcu-fsl-auto/1.0/sysroots/x86_64-fslbsp-linux/usr/lib/aarch64-fsl-linux/gcc/aarch64-fsl-linux/10.2.0/include",
],
features = features,
toolchain_identifier = "s32g-toolchain",
host_system_name = "local",
target_system_name = "unknown",
target_cpu = "unknown",
target_libc = "unknown",
compiler = "unknown",
abi_version = "unknown",
abi_libc_version = "unknown",
tool_paths = tool_paths,
builtin_sysroot = "/opt/xcu-fsl-auto/1.0/sysroots/aarch64-fsl-linux",
)

Related

bazel install io_bazel_stardoc//stardoc in bazel 3.7.2

I am using bazel 3.7.2.
I am getting this error
error loading package '#maven//': Unable to find package for #io_bazel_stardoc//stardoc:stardoc.bzl: The repository '#io_bazel_stardoc' could not be resolved.
This is my workspace
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "bazel_skylib",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
],
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
)
load("#bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()
RULES_JVM_EXTERNAL_TAG = "4.0"
RULES_JVM_EXTERNAL_SHA = "31701ad93dbfe544d597dbe62c9a1fdd76d81d8a9150c2bf1ecf928ecdf97169"
http_archive(
name = "maven",
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
sha256 = RULES_JVM_EXTERNAL_SHA,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)
load("#maven//:defs.bzl", "maven_install")
maven_install(
artifacts = [
"com.fasterxml.jackson.core:jackson-databind:2.12.1",
"org.apache.commons:commons-lang3:3.11"
],
repositories = [
"https://repo1.maven.org/maven2",
"https://jcenter.bintray.com/"
],
);
I found the solution
git_repository(
name = "io_bazel_stardoc",
remote = "https://github.com/bazelbuild/stardoc.git",
tag = "0.4.0",
)
load("#io_bazel_stardoc//:setup.bzl", "stardoc_repositories")
stardoc_repositories()

how to resolve undeclared inclusion(s) in rule while doing cross-compilation using Bazel

I'm trying to understand Bazel and do cross-compilation for a simple c++ file
Here is my example:
├── aarch64_compiler
│   ├── BUILD
│   ├── cc_toolchain_config.bzl
│   └── CROSSTOOL
├── aarch64_compiler.BUILD
├── helloworld
│   ├── BUILD.bazel
│   └── src
│   └── helloworld.cpp
└── WORKSPACE
and here is each file,
WORKSPACE
new_local_repository(
name = "aarch64_compiler",
path = "/",
build_file = "aarch64_compiler.BUILD",
)
aarch64_compiler.BUILD
package(default_visibility = ['//visibility:public'])
filegroup(
name = 'gcc',
srcs = [
'usr/bin/aarch64-linux-gnu-gcc',
],
)
filegroup(
name = 'ar',
srcs = [
'usr/bin/aarch64-linux-gnu-ar',
],
)
filegroup(
name = 'ld',
srcs = [
'usr/bin/aarch64-linux-gnu-ld',
],
)
filegroup(
name = 'nm',
srcs = [
'usr/bin/aarch64-linux-gnu-nm',
],
)
filegroup(
name = 'objcopy',
srcs = [
'usr/bin/aarch64-linux-gnu-objcopy',
],
)
filegroup(
name = 'objdump',
srcs = [
'usr/bin/aarch64-linux-gnu-objdump',
],
)
filegroup(
name = 'strip',
srcs = [
'usr/bin/aarch64-linux-gnu-strip',
],
)
filegroup(
name = 'as',
srcs = [
'usr/bin/aarch64-linux-gnu-as',
],
)
filegroup(
name = 'compiler_pieces',
srcs = glob([
'usr/lib/gcc-cross/aarch64-linux-gnu/7/**',
'usr/aarch64-linux-gnu/**',
]),
)
filegroup(
name = 'compiler_components',
srcs = [
':gcc',
':ar',
':ld',
':nm',
':objcopy',
':objdump',
':strip',
':as',
],
)
aarch64_compiler/BUILD
package(default_visibility = ["//visibility:public"])
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
cc_toolchain_suite(
name = 'toolchain',
toolchains = {
'aarch64|compiler':':gcc-linux-aarch64',
"aarch64": ":gcc-linux-aarch64",
},
)
filegroup(
name = "empty",
srcs = [],
)
filegroup(
name = "arm_linux_all_files",
srcs = [
"#aarch64_compiler//:compiler_pieces",
],
)
cc_toolchain_config(name = "aarch64_toolchain_config")
cc_toolchain(
name = 'gcc-linux-aarch64',
toolchain_identifier = "aarch64-linux-gnu",
toolchain_config = ":aarch64_toolchain_config",
all_files = ':arm_linux_all_files',
compiler_files = ':arm_linux_all_files',
#cpu = 'aarch64',
dwp_files = ':empty',
#dynamic_runtime_libs = [':empty'],
linker_files = ':arm_linux_all_files',
objcopy_files = ':arm_linux_all_files',
#static_runtime_libs = [':empty'],
strip_files = ':arm_linux_all_files',
supports_param_files = 1,
)
aarch64_compiler/cc_toolchain_config.bzl
# toolchain/cc_toolchain_config.bzl:
load("#bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "tool_path")
def _impl(ctx):
tool_paths = [
tool_path(
name = "gcc",
path = "/usr/bin/aarch64-linux-gnu-gcc",
),
tool_path(
name = "ld",
path = "/usr/bin/aarch64-linux-gnu-ld",
),
tool_path(
name = "ar",
path = "/usr/bin/aarch64-linux-gnu-ar",
),
tool_path(
name = "cpp",
path = "/usr/bin/aarch64-linux-gnu-cpp",
),
tool_path(
name = "gcov",
path = "/usr/bin/aarch64-linux-gnu-gcov",
),
tool_path(
name = "nm",
path = "/usr/bin/aarch64-linux-gnu-nm",
),
tool_path(
name = "objdump",
path = "/usr/bin/aarch64-linux-gnu-objdump",
),
tool_path(
name = "strip",
path = "/usr/bin/aarch64-linux-gnu-strip",
),
]
return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
toolchain_identifier = "aarch64-linux-gnu",
host_system_name = "x86_64-unknown-linux-gnu",
target_system_name = "aarch64-unknown-linux-gnu",
target_cpu = "aarch64",
target_libc = "unknown",
compiler = "aarch64",
abi_version = "unknown",
abi_libc_version = "unknown",
tool_paths = tool_paths,
)
cc_toolchain_config = rule(
implementation = _impl,
attrs = {},
provides = [CcToolchainConfigInfo],
)
aarch64_compiler/CROSSTOOL
major_version: "local"
minor_version: ""
default_target_cpu: "aarch64"
default_toolchain {
cpu: "aarch64"
toolchain_identifier: "aarch64-linux-gnu"
}
toolchain {
abi_version: "aarch64"
abi_libc_version: "aarch64"
builtin_sysroot: ""
compiler: "compiler"
host_system_name: "aarch64"
needsPic: true
supports_gold_linker: true
supports_incremental_linker: false
supports_fission: false
supports_interface_shared_objects: false
supports_normalizing_ar: false
supports_start_end_lib: true
target_libc: "aarch64"
target_cpu: "aarch64"
target_system_name: "aarch64"
toolchain_identifier: "aarch64-linux-gnu"
cxx_flag: "-std=c++11"
linker_flag: "-lstdc++"
linker_flag: "-lm"
linker_flag: "-fuse-ld=gold"
linker_flag: "-Wl,-no-as-needed"
linker_flag: "-Wl,-z,relro,-z,now"
linker_flag: "-pass-exit-codes"
cxx_builtin_include_directory: "/usr/aarch64-linux-gnu/include/c++/7/"
cxx_builtin_include_directory: "/usr/aarch64-linux-gnu/include/c++/7/backward"
cxx_builtin_include_directory: "/usr/aarch64-linux-gnu/include/"
cxx_builtin_include_directory: "/usr/lib/gcc-cross/aarch64-linux-gnu/7/include"
cxx_builtin_include_directory: "/usr/lib/gcc-cross/aarch64-linux-gnu/7/include-fixed"
objcopy_embed_flag: "-I"
objcopy_embed_flag: "binary"
unfiltered_cxx_flag: "-fno-canonical-system-headers"
unfiltered_cxx_flag: "-Wno-builtin-macro-redefined"
unfiltered_cxx_flag: "-D__DATE__=\"redacted\""
unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\""
unfiltered_cxx_flag: "-D__TIME__=\"redacted\""
compiler_flag: "-U_FORTIFY_SOURCE"
compiler_flag: "-fstack-protector"
compiler_flag: "-Wall"
compiler_flag: "-Wunused-but-set-parameter"
compiler_flag: "-Wno-free-nonheap-object"
compiler_flag: "-fno-omit-frame-pointer"
tool_path { name: "ld" path: "/usr/bin/aarch64-linux-gnu-ld" }
tool_path { name: "cpp" path: "/usr/bin/aarch64-linux-gnu-cpp" }
tool_path { name: "dwp" path: "/usr/bin/aarch64-linux-gnu-dwp" }
tool_path { name: "gcov" path: "/usr/bin/aarch64-linux-gnu-gcov" }
tool_path { name: "nm" path: "/usr/bin/aarch64-linux-gnu-nm" }
tool_path { name: "objcopy" path: "/usr/bin/aarch64-linux-gnu-objcopy" }
tool_path { name: "objdump" path: "/usr/bin/aarch64-linux-gnu-objdump" }
tool_path { name: "strip" path: "/usr/bin/aarch64-linux-gnu-strip" }
tool_path { name: "gcc" path: "/usr/bin/aarch64-linux-gnu-gcc" }
tool_path { name: "ar" path: "/usr/bin/aarch64-linux-gnu-ar" }
compilation_mode_flags {
mode: DBG
# Enable debug symbols.
compiler_flag: "-g"
}
compilation_mode_flags {
mode: OPT
# No debug symbols.
# Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or
# even generally? However, that can't happen here, as it requires special
# handling in Bazel.
compiler_flag: "-g0"
# Conservative choice for -O
# -O3 can increase binary size and even slow down the resulting binaries.
# Profile first and / or use FDO if you need better performance than this.
compiler_flag: "-O2"
compiler_flag: "-D_FORTIFY_SOURCE=1"
# Disable assertions
compiler_flag: "-DNDEBUG"
# Removal of unused code and data at link time (can this increase binary size in some cases?).
compiler_flag: "-ffunction-sections"
compiler_flag: "-fdata-sections"
linker_flag: "-Wl,--gc-sections"
}
linking_mode_flags { mode: DYNAMIC }
feature {
name: 'coverage'
provides: 'profile'
flag_set {
action: 'preprocess-assemble'
action: 'c-compile'
action: 'c++-compile'
action: 'c++-header-parsing'
action: 'c++-header-preprocessing'
action: 'c++-module-compile'
flag_group {
flag: '-fprofile-arcs'
flag: '-ftest-coverage'
}
}
flag_set {
action: 'c++-link-interface-dynamic-library'
action: 'c++-link-dynamic-library'
action: 'c++-link-executable'
flag_group {
flag: '-lgcov'
}
}
}
}
helloworld/BUILD.bazel
cc_binary(
name = "helloworld",
srcs = [ "src/helloworld.cpp" ],
)
helloworld/src/helloworld.cpp
#include <iostream>
int main() {
std::cout << "Hello World from BAZEL" << std::endl;
}
The bazel command used: bazel build //helloworld:helloworld --cpu=aarch64 --crosstool_top=//aarch64_compiler:toolchain --host_crosstool_top=#bazel_tools//tools/cpp:toolchain --verbose_failures
and I got this error:
ERROR: /data/cross-compile/bazel_sample/helloworld/BUILD.bazel:1:1: undeclared inclusion(s) in rule '//helloworld:helloworld':
this rule is missing dependency declarations for the following files included by 'helloworld/src/helloworld.cpp':
'/usr/aarch64-linux-gnu/include/stdc-predef.h'
'/usr/aarch64-linux-gnu/include/c++/7/iostream'
'/usr/aarch64-linux-gnu/include/c++/7/aarch64-linux-gnu/bits/c++config.h'
'/usr/aarch64-linux-gnu/include/c++/7/aarch64-linux-gnu/bits/os_defines.h'
'/usr/aarch64-linux-gnu/include/features.h'
'/usr/aarch64-linux-gnu/include/sys/cdefs.h'
'/usr/aarch64-linux-gnu/include/bits/wordsize.h'
'/usr/aarch64-linux-gnu/include/bits/long-double.h'
'/usr/aarch64-linux-gnu/include/gnu/stubs.h'
.....
what is the missing in my configurations?
There are 2 things that might help:
You need to include these search path in the compilation command with compiler_flag.
You might also need to add -no-canonical-prefixes in compiler_flag, otherwise bazel might not be able to match understand that the path used is the same as the one declared.

How can I build SBTUITestTunnel for a Swift app using Buck?

I am trying to use Buck to include the SBTUITestTunnel library in a couple of iOS apps I am working on. This library extends the standard Xcode UI-testing framework to offer additional features such as monitoring network calls. While SBTUITestTunnel is written mostly in Objective-C, The apps I hope to include this library in are written in Swift and use Buck as their build tool. I'd also like to be able to use both Buck and Xcode to execute the tests once I have them written.
Unfortunately, the SBTUITestTunnel Installation/Setup/Usage docs do not seem to provide any guidance on building them with Buck. The repo does include CocoaPods config files, which I have tried to convert to a BUCK file. However, I've been unable to get that working properly after several attempts. I've even tried grabbing the prebuilt .frameworks from the build output of the provided SBTUITestTunnel Example App, but still no luck.
Here are the attempts I've made so far at creating a working BUCK file:
Attempt 1 - Building as Libraries from Source:
Code:
apple_library(
name = 'SBTUITestTunnelCommon',
visibility = ['PUBLIC'],
swift_version = '5',
exported_headers = glob([
'Pod/Common/**/*.h',
]),
srcs = glob([
'Pod/Common/**/*.swift',
'Pod/Common/**/*.m',
]),
deps = [
'//Path/GCDWebServer:GCDWebServer',
]
)
apple_library(
name = 'SBTUITestTunnelClient',
visibility = ['PUBLIC'],
swift_version = '5',
exported_headers = glob([
'Pod/Client/**/*.h',
]),
srcs = glob([
'Pod/Client/**/*.swift',
'Pod/Client/**/*.m',
]),
deps = [
'//Path/GCDWebServer:GCDWebServer',
'//Path/SBTUITestTunnel:SBTUITestTunnelCommon',
]
)
apple_library(
name = 'SBTUITestTunnelServer',
visibility = ['PUBLIC'],
swift_version = '5',
exported_headers = glob([
'Pod/Server/**/*.h',
]),
srcs = glob([
'Pod/Server/**/*.swift',
'Pod/Server/**/*.m',
]),
deps = [
'//Path/GCDWebServer:GCDWebServer',
'//Path/SBTUITestTunnel:SBTUITestTunnelCommon',
]
)
Result:
Buck build completes successfully, but running tests in Buck and trying to build in Xcode both fail due with errors like this one (when trying to run #import SBTUITestTunnelCommon; from a file in the SBTUITestTunnelServer class):
Module 'SBTUITestTunnelCommon' not found
Attempt 2 - Building as Frameworks from Source:
Code:
sbt_ui_test_tunnel_common_bundle_name = 'SBTUITestTunnelCommon'
sbt_ui_test_tunnel_common_binary_name = sbt_ui_test_tunnel_common_bundle_name + 'Binary'
sbt_ui_test_tunnel_common_module_name = sbt_ui_test_tunnel_common_bundle_name
sbt_ui_test_tunnel_common_product_name = sbt_ui_test_tunnel_common_bundle_name
# Copied `Info.plist` from the Example app to this Pod folder:
sbt_ui_test_tunnel_common_info_plist = 'Pod/Common/' + sbt_ui_test_tunnel_common_bundle_name + '-Info.plist'
sbt_ui_test_tunnel_client_bundle_name = 'SBTUITestTunnelClient'
sbt_ui_test_tunnel_client_binary_name = sbt_ui_test_tunnel_client_bundle_name + 'Binary'
sbt_ui_test_tunnel_client_module_name = sbt_ui_test_tunnel_client_bundle_name
sbt_ui_test_tunnel_client_product_name = sbt_ui_test_tunnel_client_bundle_name
# Copied `Info.plist` from the Example app to this Pod folder:
sbt_ui_test_tunnel_client_info_plist = 'Pod/Client/' + sbt_ui_test_tunnel_client_bundle_name + '-Info.plist'
sbt_ui_test_tunnel_server_bundle_name = 'SBTUITestTunnelServer'
sbt_ui_test_tunnel_server_binary_name = sbt_ui_test_tunnel_server_bundle_name + 'Binary'
sbt_ui_test_tunnel_server_module_name = sbt_ui_test_tunnel_server_bundle_name
sbt_ui_test_tunnel_server_product_name = sbt_ui_test_tunnel_server_bundle_name
# Copied `Info.plist` from the Example app to this Pod folder:
sbt_ui_test_tunnel_server_info_plist = 'Pod/Server/' + sbt_ui_test_tunnel_server_bundle_name + '-Info.plist'
apple_binary(
name = sbt_ui_test_tunnel_common_binary_name,
visibility = ['PUBLIC'],
module_name = sbt_ui_test_tunnel_common_module_name,
swift_version = '5',
linker_flags = [
'-ObjC', # Have tried with and without this
],
link_style = 'shared',
exported_headers = glob([
'Pod/Common/**/*.h',
]),
srcs = glob([
'Pod/Common/**/*.swift',
'Pod/Common/**/*.m',
]),
deps = [
'//Path/GCDWebServer:GCDWebServer',
]
)
apple_bundle(
name = sbt_ui_test_tunnel_common_bundle_name,
visibility = ['PUBLIC'],
product_name = sbt_ui_test_tunnel_common_product_name,
binary = ':' + sbt_ui_test_tunnel_common_binary_name,
extension = 'framework',
xcode_product_type = 'com.apple.product-type.framework',
info_plist = sbt_ui_test_tunnel_common_info_plist,
)
apple_binary(
name = sbt_ui_test_tunnel_client_binary_name,
visibility = ['PUBLIC'],
module_name = sbt_ui_test_tunnel_client_module_name,
swift_version = '5',
linker_flags = [
'-ObjC', # Have tried with and without this
],
link_style = 'shared',
exported_headers = glob([
'Pod/Client/**/*.h',
]),
srcs = glob([
'Pod/Client/**/*.swift',
'Pod/Client/**/*.m',
]),
deps = [
'//Path/GCDWebServer:GCDWebServer',
'//Path/SBTUITestTunnel:' + sbt_ui_test_tunnel_common_binary_name,
]
)
apple_bundle(
name = sbt_ui_test_tunnel_client_bundle_name,
visibility = ['PUBLIC'],
product_name = sbt_ui_test_tunnel_client_product_name,
binary = ':' + sbt_ui_test_tunnel_client_binary_name,
extension = 'framework',
xcode_product_type = 'com.apple.product-type.framework',
info_plist = sbt_ui_test_tunnel_client_info_plist,
)
apple_binary(
name = sbt_ui_test_tunnel_server_binary_name,
visibility = ['PUBLIC'],
module_name = sbt_ui_test_tunnel_server_module_name,
swift_version = '5',
enter code here
linker_flags = [
'-ObjC', # Have tried with and without this
],
link_style = 'shared',
exported_headers = glob([
'Pod/Server/**/*.h',
]),
srcs = glob([
'Pod/Server/**/*.swift',
'Pod/Server/**/*.m',
]),
deps = [
'//Path/GCDWebServer:GCDWebServer',
'//Path/SBTUITestTunnel:' + sbt_ui_test_tunnel_common_binary_name,
]
)
apple_bundle(
name = sbt_ui_test_tunnel_server_bundle_name,
visibility = ['PUBLIC'],
product_name = sbt_ui_test_tunnel_server_product_name,
binary = ':' + sbt_ui_test_tunnel_server_binary_name,
extension = 'framework',
xcode_product_type = 'com.apple.product-type.framework',
info_plist = sbt_ui_test_tunnel_server_info_plist,
)
Result:
Buck build fails with this error message:
Command failed with exit code 1.
stderr: ld: warning: -sdk_version and -platform_version are not compatible, ignoring -
sdk_version
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Attempt 3 - Building as prebuilt_apple_frameworks:
Code:
sbt_ui_test_tunnel_common_framework_name = 'SBTUITestTunnelCommon'
# Copied .framework file from build output of the Example app to this Frameworks folder:
sbt_ui_test_tunnel_common_framework_path = 'Frameworks/' + sbt_ui_test_tunnel_common_framework_name + '/' + sbt_ui_test_tunnel_common_framework_name + '.framework'
sbt_ui_test_tunnel_client_framework_name = 'SBTUITestTunnelClient'
# Copied .framework file from build output of the Example app to this Frameworks folder:
sbt_ui_test_tunnel_client_framework_path = 'Frameworks/' + sbt_ui_test_tunnel_common_framework_name + '/' + sbt_ui_test_tunnel_common_framework_name + '.framework'
sbt_ui_test_tunnel_server_framework_name = 'SBTUITestTunnelServer'
# Copied .framework file from build output of the Example app to this Frameworks folder:
sbt_ui_test_tunnel_server_framework_path = 'Frameworks/' + sbt_ui_test_tunnel_common_framework_name + '/' + sbt_ui_test_tunnel_common_framework_name + '.framework'
prebuilt_apple_framework(
name = sbt_ui_test_tunnel_common_framework_name,
framework = sbt_ui_test_tunnel_common_framework_path,
preferred_linkage = 'stat',
visibility = [
'PUBLIC'
],
deps = [
'//Path/GCDWebServer:GCDWebServer',
],
)
prebuilt_apple_framework(
name = sbt_ui_test_tunnel_client_framework_name,
framework = sbt_ui_test_tunnel_client_framework_path,
preferred_linkage = 'shared',
visibility = [
'PUBLIC'
],
deps = [
'//Path/GCDWebServer:GCDWebServer',
'//Path/SBTUITestTunnel:' + sbt_ui_test_tunnel_common_framework_name,
],
)
prebuilt_apple_framework(
name = sbt_ui_test_tunnel_server_framework_name,
framework = sbt_ui_test_tunnel_server_framework_path,
preferred_linkage = 'shared',
visibility = [
'PUBLIC'
],
deps = [
'//Path/GCDWebServer:GCDWebServer',
'//Path/SBTUITestTunnel:' + sbt_ui_test_tunnel_common_framework_name,
],
)
Result:
Buck build fails with this error message:
Command failed with exit code 1.
stderr: /Users/me/path/BridgingHeader.h:12:9: error: 'SBTUITestTunnelServer/SBTUITestTunnelServer.h' file not found
#import <SBTUITestTunnelServer/SBTUITestTunnelServer.h>
^
<unknown>:0: error: failed to import bridging header 'path/BridgingHeader.h'
Additional Notes:
I've followed all steps in the docs, including setting the DEBUG/DEBUG=1 settings and adding the necessary dependencies in the BridgingHeaders.h files like so:
In the Bridging Header file for the library that is to be tested:
#import <SBTUITestTunnelCommon/SBTUITestTunnelCommon.h>
#import <SBTUITestTunnelServer/SBTUITestTunnelServer.h>
And in the Bridging Header file for the library that has the tests:
#import <SBTUITestTunnelClient/SBTUITunneledApplication.h>
#import <SBTUITestTunnelClient/XCTestCase+AppExtension.h>
#import <SBTUITestTunnelCommon/SBTUITestTunnelCommon.h> // Have tried with and without this line
I included the SBTUITestTunnel libraries/frameworks as dependencies in my main app's BUCK file like this:
apple_library(
...
bridging_header = 'BridgingHeader.h',
deps = [
'//Path/SBTUITestTunnel:SBTUITestTunnelCommon',
'//Path/SBTUITestTunnel:SBTUITestTunnelServer',
'//Path/GCDWebServer:GCDWebServer',
]
)
apple_test(
...
bridging_header = 'UITests/BridgingHeader.h',
deps = [
'//Path/SBTUITestTunnel:SBTUITestTunnelClient',
]
)
SBTUITestTunnel depends on another library, GCDWebServer, which also does not provide a BUCK file. However, I have been able to get that one working with using this:
apple_library(
name = 'GCDWebServer',
visibility = ['PUBLIC'],
swift_version = '5',
exported_headers = glob([
'GCDWebServer/**/*.h',
]),
srcs = glob([
'GCDWebServer/**/*.swift',
'GCDWebServer/**/*.m',
])
)
apple_library(
name = 'GCDWebDAVServer',
visibility = ['PUBLIC'],
swift_version = '5',
exported_headers = glob([
'GCDWebDAVServer/**/*.h',
]),
srcs = glob([
'GCDWebDAVServer/*.swift',
'GCDWebDAVServer/*.m',
]),
deps = [
'//Path/GCDWebServer:GCDWebServer',
]
)
apple_library(
name = 'GCDWebUploader',
visibility = ['PUBLIC'],
swift_version = '5',
exported_headers = glob([
'GCDWebUploader/**/*.h',
]),
srcs = glob([
'GCDWebUploader/**/*.swift',
'GCDWebUploader/**/*.m',
]),
deps = [
'//Path/GCDWebServer:GCDWebServer',
]
)
Any idea what I am doing wrong? Or at least maybe some advice on which of these options is most likely the best path?

What is the most efficient way to extract/collect files from a list of targets/providers in Bazel?

I'm writing some rules and learning Starlark as I progress.
Assume I have my own provider:
ModularResources = provider(
doc = "Modular resources",
fields = {
"artifactId": "Former Maven artifact id (don't ask me why)",
"srcs": "List of labels (a glob(..) thing)",
},
)
def _modular_resources_impl(ctx):
return ModularResources(
artifactId = ctx.attr.artifactId,
srcs = ctx.attr.srcs,
)
modular_resources = rule(
implementation = _modular_resources_impl,
attrs = {
"artifactId": attr.string(
mandatory = True,
),
"srcs": attr.label_list(
allow_files = True,
mandatory = True,
),
},
)
Then I have a generator rule which requires these:
some_generator = rule(
attrs = {
"deps": attr.label_list(
providers = [ ModularResources ]
),
...
},
...
)
In my implementation I discovered that I need to do a couple of unwraps to get the files:
def _get_files(deps):
result = []
for dep in deps:
for target in dep[ModularResources].srcs:
result += target.files.to_list()
return result
Is there a more efficient way to perform the collection?
As to why I'm doing this, the generator actually needs a special list of files like this:
def _format_files(deps):
formatted = ""
for dep in deps:
for target in dep[ModularResources].srcs:
formatted += ",".join([dep[ModularResources].artifactId + ":" + f.path for f in target.files.to_list()])
return formatted
FWIW, here is an example how this is used:
a/BUILD:
modular_resources(
name = "generator_resources",
srcs = glob(
["some/path/**/*.whatever"],
),
artifactId = "a",
visibility = ["//visibility:public"],
)
b/BUILD:
some_generator(
name = "...",
deps = [
"//a:generator_resources"
]
)
If you want to trade memory for better performance, maybe the operation can more easily be parallelised by blaze if it's done in the provider instead:
def _modular_resources_impl(ctx):
return ModularResources(
artifactId = ctx.attr.artifactId,
formatted_srcs = ",".join([artifactId + ":" + f.path for f in ctx.files.src])
)

Bazel: testng macro

I'm trying to create a macro in Bazel to wrap java_test to run testng, however I'm running into trouble passing TestNG the filename
So far I have
load("#bazel_skylib//:lib.bzl", "paths")
def java_testng(file, deps=[], **kwargs):
native.java_test(
name = paths.split_extension(file)[0],
srcs = [file],
use_testrunner=False,
main_class='org.testng.TestNG',
deps = [
"//third_party:org_testng_testng"
] + deps,
args=[file],
**kwargs
)
However args seems to be a non-existent runfile.
Help appreciated on the correct value for args
Here is a sample usage I would like
java_testng(
file = "SomeFakeTest.java",
deps = [
"//:resources",
"//third_party:com_fasterxml_jackson_core_jackson_databind",
"//third_party:org_assertj_assertj_core",
],
)
Here is the solution I came up with
load("#bazel_skylib//:lib.bzl", "paths")
def java_testng(file, deps=[], size="small", **kwargs):
native.java_library(
name = paths.split_extension(file)[0] + "-lib",
deps = [
"//third_party:org_testng_testng"
] + deps,
srcs = [file]
)
native.java_test(
name = paths.split_extension(file)[0],
use_testrunner=False,
main_class='org.testng.TestNG',
runtime_deps = [
"//third_party:org_testng_testng",
paths.split_extension(file)[0] + "-lib"
],
data = [file],
size = size,
args=["-testclass $(location " + file + ")"],
**kwargs
)
I dont know why you used a macro, I manage to call testng without.
See my solution below:
I create my program jar (using some Annotation Processor)
I create my test jar (using some Annotation Processor)
I call testng via java_test().
The alone thing I didn't figure out: how to not hardcode the "libmy-model-test-lib.jar"
java_library(
name = "my-model",
srcs = glob(["src/main/java/**/*.java"]),
resources = glob(["src/main/resources/**"]),
deps = [
"#commons_logging_jar//jar",
":lombok",
":mysema_query",
...
],
)
java_library(
name = "my-model-test-lib",
srcs = glob(["src/test/java/**/*.java"]),
deps = [
"#org_hamcrest_core_jar//jar",
"#commons_logging_jar//jar",
":lombok",
":mysema_query",
...
"#assertj_jar//jar",
"#mockito_jar//jar",
"#testng_jar//jar",
],
)
java_test(
name = "AllTests",
size = "small",
runtime_deps = [
":my-model-test-lib",
":my-model",
"#org_jboss_logging_jar//jar",
"#org_objenesis_jar//jar",
"#com_beust_jcommander//jar",
],
use_testrunner=False,
main_class='org.testng.TestNG',
args=['-testjar','libmy-model-test-lib.jar','-verbose','2'],
)
java_plugin(
name = "lombok_plugin",
processor_class = "lombok.launch.AnnotationProcessorHider$AnnotationProcessor",
deps = ["#lombok_jar//jar"],
)
java_library(
name = "lombok",
exports = ["#lombok_jar//jar"],
exported_plugins = [":lombok_plugin"],
)
java_plugin(
name = "mysema_query_plugin",
processor_class = "com.mysema.query.apt.jpa.JPAAnnotationProcessor",
deps = [
"#querydsl_apt_jar//jar",
"#mysema_codegen_jar//jar",
"#javax_persistence_jar//jar",
"#querydsl_codegen_jar//jar",
"#guava_jar//jar",
"#querydsl_core_jar//jar",
"#javax_inject_jar//jar",
],
)
java_library(
name = "mysema_query",
exports = ["#querydsl_apt_jar//jar"],
exported_plugins = [":mysema_query_plugin"],
)
java_plugin(
name = "mockito_plugin",
processor_class = "",
deps = ["#mockito_jar//jar"],
)
java_library(
name = "mockito",
exports = ["#mockito_jar//jar"],
exported_plugins = [":mockito_plugin"],
)

Resources