Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

Commit cc21998

Browse files
c-parsonsdamienmg
authored andcommitted
Rollforward #2 of: Basic open-source crosstool to support targeting apple platform types.
RELNOTES: None. PiperOrigin-RevId: 154993630
1 parent 655c07b commit cc21998

File tree

11 files changed

+5643
-5309
lines changed

11 files changed

+5643
-5309
lines changed

src/test/shell/bazel/apple/bazel_apple_test.sh

Lines changed: 133 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ EOF
212212
bazel build --verbose_failures --objccopt=-DCOPTS_FOO=1 -s \
213213
--xcode_version=$XCODE_VERSION \
214214
//ios:swift_lib >$TEST_log 2>&1 || fail "should build"
215-
expect_log "-module-cache-path bazel-out/local-fastbuild/genfiles/_objc_module_cache"
215+
expect_log "-module-cache-path bazel-out/darwin_x86_64-fastbuild/genfiles/_objc_module_cache"
216216
}
217217

218218
function test_swift_import_objc_framework() {
@@ -766,8 +766,8 @@ EOF
766766

767767
bazel build --verbose_failures --xcode_version=$XCODE_VERSION -s \
768768
//ios:bin >$TEST_log 2>&1 || fail "should build"
769-
expect_log "-Xlinker -add_ast_path -Xlinker bazel-out/local-fastbuild/genfiles/ios/dep/_objs/ios_dep.swiftmodule"
770-
expect_log "-Xlinker -add_ast_path -Xlinker bazel-out/local-fastbuild/genfiles/ios/swift_lib/_objs/ios_swift_lib.swiftmodule"
769+
expect_log "-Xlinker -add_ast_path -Xlinker bazel-out/darwin_x86_64-fastbuild/genfiles/ios/dep/_objs/ios_dep.swiftmodule"
770+
expect_log "-Xlinker -add_ast_path -Xlinker bazel-out/darwin_x86_64-fastbuild/genfiles/ios/swift_lib/_objs/ios_swift_lib.swiftmodule"
771771
}
772772

773773
function test_swiftc_script_mode() {
@@ -914,4 +914,134 @@ EOF
914914
|| fail "should contain DWARF data"
915915
}
916916

917+
function test_apple_binary_crosstool_ios() {
918+
rm -rf package
919+
mkdir -p package
920+
cat > package/BUILD <<EOF
921+
objc_library(
922+
name = "lib_a",
923+
srcs = ["a.m"],
924+
)
925+
objc_library(
926+
name = "lib_b",
927+
srcs = ["b.m"],
928+
deps = [":cc_lib"],
929+
)
930+
cc_library(
931+
name = "cc_lib",
932+
srcs = ["cc_lib.cc"],
933+
)
934+
apple_binary(
935+
name = "main_binary",
936+
deps = [":lib_a", ":lib_b"],
937+
srcs = ["main.m"],
938+
)
939+
genrule(
940+
name = "lipo_run",
941+
srcs = [":main_binary_lipobin"],
942+
outs = ["lipo_out"],
943+
cmd =
944+
"set -e && " +
945+
"lipo -info \$(location :main_binary_lipobin) > \$(@)",
946+
tags = ["requires-darwin"],
947+
)
948+
EOF
949+
touch package/a.m
950+
touch package/b.m
951+
cat > package/main.m <<EOF
952+
int main() {
953+
return 0;
954+
}
955+
EOF
956+
cat > package/cc_lib.cc << EOF
957+
#include <string>
958+
959+
std::string GetString() { return "h3ll0"; }
960+
EOF
961+
962+
bazel build --verbose_failures //package:lipo_out \
963+
--experimental_enable_objc_cc_deps \
964+
--experimental_objc_crosstool=all \
965+
--apple_crosstool_transition \
966+
--ios_multi_cpus=i386,x86_64 \
967+
--xcode_version=$XCODE_VERSION \
968+
|| fail "should build apple_binary and obtain info via lipo"
969+
970+
cat bazel-genfiles/package/lipo_out | grep "i386 x86_64" \
971+
|| fail "expected output binary to be for x86_64 architecture"
972+
}
973+
974+
function test_apple_binary_crosstool_watchos() {
975+
rm -rf package
976+
mkdir -p package
977+
cat > package/BUILD <<EOF
978+
genrule(
979+
name = "lipo_run",
980+
srcs = [":main_binary_lipobin"],
981+
outs = ["lipo_out"],
982+
cmd =
983+
"set -e && " +
984+
"lipo -info \$(location :main_binary_lipobin) > \$(@)",
985+
tags = ["requires-darwin"],
986+
)
987+
988+
apple_binary(
989+
name = "main_binary",
990+
srcs = ["main.m"],
991+
deps = [":lib_a"],
992+
platform_type = "watchos",
993+
)
994+
cc_library(
995+
name = "cc_lib",
996+
srcs = ["cc_lib.cc"],
997+
)
998+
# By depending on a library which requires it is built for watchos,
999+
# this test verifies that dependencies of apple_binary are compiled
1000+
# for the specified platform_type.
1001+
objc_library(
1002+
name = "lib_a",
1003+
srcs = ["a.m"],
1004+
deps = [":cc_lib"],
1005+
)
1006+
EOF
1007+
cat > package/main.m <<EOF
1008+
#import <WatchKit/WatchKit.h>
1009+
1010+
// Note that WKExtensionDelegate is only available in Watch SDK.
1011+
@interface TestInterfaceMain : NSObject <WKExtensionDelegate>
1012+
@end
1013+
1014+
int main() {
1015+
return 0;
1016+
}
1017+
EOF
1018+
cat > package/a.m <<EOF
1019+
#import <WatchKit/WatchKit.h>
1020+
1021+
// Note that WKExtensionDelegate is only available in Watch SDK.
1022+
@interface TestInterfaceA : NSObject <WKExtensionDelegate>
1023+
@end
1024+
1025+
int aFunction() {
1026+
return 0;
1027+
}
1028+
EOF
1029+
cat > package/cc_lib.cc << EOF
1030+
#include <string>
1031+
1032+
std::string GetString() { return "h3ll0"; }
1033+
EOF
1034+
1035+
bazel build --verbose_failures //package:lipo_out \
1036+
--experimental_enable_objc_cc_deps \
1037+
--experimental_objc_crosstool=library \
1038+
--apple_crosstool_transition \
1039+
--watchos_cpus=armv7k \
1040+
--xcode_version=$XCODE_VERSION \
1041+
|| fail "should build watch binary"
1042+
1043+
cat bazel-genfiles/package/lipo_out | grep "armv7k" \
1044+
|| fail "expected output binary to be for armv7k architecture"
1045+
}
1046+
9171047
run_suite "apple_tests"

src/test/shell/bazel/external_correctness_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ genrule(
142142
)
143143
EOF
144144
bazel build @a//b/c:echo-d &> $TEST_log || fail "Build failed"
145-
assert_contains "bazel-out/local.*-fastbuild/genfiles/external/a/b/c" \
145+
assert_contains "bazel-out/.*-fastbuild/genfiles/external/a/b/c" \
146146
"bazel-genfiles/external/a/b/c/d"
147147
}
148148

src/test/shell/bazel/remote_execution_test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ function tear_down() {
5353
}
5454

5555
function test_cc_binary() {
56+
if [[ "$PLATFORM" == "darwin" ]]; then
57+
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
58+
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
59+
# action executors in order to select the appropriate Xcode toolchain.
60+
return 0
61+
fi
62+
5663
mkdir -p a
5764
cat > a/BUILD <<EOF
5865
package(default_visibility = ["//visibility:public"])

0 commit comments

Comments
 (0)