Skip to content
Snippets Groups Projects
Commit 04012f0a authored by Dragoș Tiselice's avatar Dragoș Tiselice Committed by CQ bot account: commit-bot@chromium.org
Browse files

[build] Fix Rust static library dependecies

Depending on a static_library from Rust fails because the correct
link directory path is not passed to build_rustc_target.py. This
fix adds link paths from every one of the dependecies found in
non_rust_deps.

This is not ideal since it doesn't work with source_set or any
shared library that has transitive dependencies.

TEST=Build, CQ, and Rust crate that tests scenario.
     fx run-test static_library_tests

Change-Id: I42c2d07e68d5f7a3d76c0edacbcd0d81f50c4993
parent 56a0f396
No related branches found
No related tags found
No related merge requests found
......@@ -448,6 +448,15 @@ template("rustc_artifact") {
args += [ "--with-unit-tests" ]
}
if (defined(invoker.non_rust_deps)) {
foreach(dep, invoker.non_rust_deps) {
args += [
"--lib-dir",
rebase_path(get_label_info(dep, "target_out_dir")),
]
}
}
args += dep_info_paths
outputs = [
output_file,
......
......@@ -17,5 +17,6 @@ group("tests") {
testonly = true
deps = [
"hello_world:tests",
"rust_static_linking:static_linking_tests",
]
}
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/package.gni")
import("//build/rust/rustc_library.gni")
rustc_library("static_linking") {
name = "static_linking"
with_unit_tests = true
version = "0.1.0"
edition = "2018"
non_rust_deps = [
":static",
]
}
static_library("static") {
sources = [
"static.c",
]
}
package("static_linking_tests") {
testonly = true
deps = [
":static_linking",
]
tests = [
{
name = "static_linking_lib_test"
},
]
}
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#[link(name = "static", kind = "static")]
extern "C" {
pub fn returns_two() -> u32;
}
#[cfg(test)]
mod tests {
use super::returns_two;
#[test]
fn linking_works() {
assert_eq!(unsafe { returns_two() }, 2);
}
}
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdint.h>
uint32_t returns_two() {
return 2;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment