blob: bf8643efb0b5079be48bdea02f83feec885fc7d8 [file] [log] [blame]
Ivan Lozanoffee3342019-08-27 12:03:00 -07001// Copyright 2019 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package rust
16
17import (
18 "strings"
19 "testing"
20)
21
22// Test that variants are being generated correctly, and that crate-types are correct.
23func TestLibraryVariants(t *testing.T) {
24
25 ctx := testRust(t, `
26 rust_library_host {
27 name: "libfoo",
28 srcs: ["foo.rs"],
29 crate_name: "foo",
30 }`)
31
32 // Test both variants are being built.
33 libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib").Output("libfoo.rlib")
34 libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Output("libfoo.so")
35
36 // Test crate type for rlib is correct.
37 if !strings.Contains(libfooRlib.Args["rustcFlags"], "crate-type=rlib") {
38 t.Errorf("missing crate-type for libfoo rlib, rustcFlags: %#v", libfooRlib.Args["rustcFlags"])
39 }
40
41 // Test crate type for dylib is correct.
42 if !strings.Contains(libfooDylib.Args["rustcFlags"], "crate-type=dylib") {
43 t.Errorf("missing crate-type for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
44 }
45}
46
47// Test that dylibs are not statically linking the standard library.
48func TestDylibPreferDynamic(t *testing.T) {
49 ctx := testRust(t, `
50 rust_library_host_dylib {
51 name: "libfoo",
52 srcs: ["foo.rs"],
53 crate_name: "foo",
54 }`)
55
56 libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Output("libfoo.so")
57
58 if !strings.Contains(libfooDylib.Args["rustcFlags"], "prefer-dynamic") {
59 t.Errorf("missing prefer-dynamic flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
60 }
61}