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

Commit

Permalink
Rollforward #2 of: Basic open-source crosstool to support targeting a…
Browse files Browse the repository at this point in the history
…pple platform types.

RELNOTES: None.
PiperOrigin-RevId: 154993630
  • Loading branch information
c-parsons authored and damienmg committed May 4, 2017
1 parent 655c07b commit cc21998
Show file tree
Hide file tree
Showing 11 changed files with 5,643 additions and 5,309 deletions.
136 changes: 133 additions & 3 deletions src/test/shell/bazel/apple/bazel_apple_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ EOF
bazel build --verbose_failures --objccopt=-DCOPTS_FOO=1 -s \
--xcode_version=$XCODE_VERSION \
//ios:swift_lib >$TEST_log 2>&1 || fail "should build"
expect_log "-module-cache-path bazel-out/local-fastbuild/genfiles/_objc_module_cache"
expect_log "-module-cache-path bazel-out/darwin_x86_64-fastbuild/genfiles/_objc_module_cache"
}

function test_swift_import_objc_framework() {
Expand Down Expand Up @@ -766,8 +766,8 @@ EOF

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

function test_swiftc_script_mode() {
Expand Down Expand Up @@ -914,4 +914,134 @@ EOF
|| fail "should contain DWARF data"
}

function test_apple_binary_crosstool_ios() {
rm -rf package
mkdir -p package
cat > package/BUILD <<EOF
objc_library(
name = "lib_a",
srcs = ["a.m"],
)
objc_library(
name = "lib_b",
srcs = ["b.m"],
deps = [":cc_lib"],
)
cc_library(
name = "cc_lib",
srcs = ["cc_lib.cc"],
)
apple_binary(
name = "main_binary",
deps = [":lib_a", ":lib_b"],
srcs = ["main.m"],
)
genrule(
name = "lipo_run",
srcs = [":main_binary_lipobin"],
outs = ["lipo_out"],
cmd =
"set -e && " +
"lipo -info \$(location :main_binary_lipobin) > \$(@)",
tags = ["requires-darwin"],
)
EOF
touch package/a.m
touch package/b.m
cat > package/main.m <<EOF
int main() {
return 0;
}
EOF
cat > package/cc_lib.cc << EOF
#include <string>
std::string GetString() { return "h3ll0"; }
EOF

bazel build --verbose_failures //package:lipo_out \
--experimental_enable_objc_cc_deps \
--experimental_objc_crosstool=all \
--apple_crosstool_transition \
--ios_multi_cpus=i386,x86_64 \
--xcode_version=$XCODE_VERSION \
|| fail "should build apple_binary and obtain info via lipo"

cat bazel-genfiles/package/lipo_out | grep "i386 x86_64" \
|| fail "expected output binary to be for x86_64 architecture"
}

function test_apple_binary_crosstool_watchos() {
rm -rf package
mkdir -p package
cat > package/BUILD <<EOF
genrule(
name = "lipo_run",
srcs = [":main_binary_lipobin"],
outs = ["lipo_out"],
cmd =
"set -e && " +
"lipo -info \$(location :main_binary_lipobin) > \$(@)",
tags = ["requires-darwin"],
)
apple_binary(
name = "main_binary",
srcs = ["main.m"],
deps = [":lib_a"],
platform_type = "watchos",
)
cc_library(
name = "cc_lib",
srcs = ["cc_lib.cc"],
)
# By depending on a library which requires it is built for watchos,
# this test verifies that dependencies of apple_binary are compiled
# for the specified platform_type.
objc_library(
name = "lib_a",
srcs = ["a.m"],
deps = [":cc_lib"],
)
EOF
cat > package/main.m <<EOF
#import <WatchKit/WatchKit.h>
// Note that WKExtensionDelegate is only available in Watch SDK.
@interface TestInterfaceMain : NSObject <WKExtensionDelegate>
@end
int main() {
return 0;
}
EOF
cat > package/a.m <<EOF
#import <WatchKit/WatchKit.h>
// Note that WKExtensionDelegate is only available in Watch SDK.
@interface TestInterfaceA : NSObject <WKExtensionDelegate>
@end
int aFunction() {
return 0;
}
EOF
cat > package/cc_lib.cc << EOF
#include <string>
std::string GetString() { return "h3ll0"; }
EOF

bazel build --verbose_failures //package:lipo_out \
--experimental_enable_objc_cc_deps \
--experimental_objc_crosstool=library \
--apple_crosstool_transition \
--watchos_cpus=armv7k \
--xcode_version=$XCODE_VERSION \
|| fail "should build watch binary"

cat bazel-genfiles/package/lipo_out | grep "armv7k" \
|| fail "expected output binary to be for armv7k architecture"
}

run_suite "apple_tests"
2 changes: 1 addition & 1 deletion src/test/shell/bazel/external_correctness_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ genrule(
)
EOF
bazel build @a//b/c:echo-d &> $TEST_log || fail "Build failed"
assert_contains "bazel-out/local.*-fastbuild/genfiles/external/a/b/c" \
assert_contains "bazel-out/.*-fastbuild/genfiles/external/a/b/c" \
"bazel-genfiles/external/a/b/c/d"
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/shell/bazel/remote_execution_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ function tear_down() {
}

function test_cc_binary() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

mkdir -p a
cat > a/BUILD <<EOF
package(default_visibility = ["//visibility:public"])
Expand Down
Loading

0 comments on commit cc21998

Please sign in to comment.