Separate zircon build is gone

Pull bits and pieces from their new locations and
add the C runtime as a link parameter, as that
also appears to be needed now.

Change-Id: I35ee5da191036174f12cc793321ac3e4910b7ef8
Reviewed-on: https://fuchsia-review.googlesource.com/c/fargo/+/473857
Reviewed-by: Tyler Mandry <tmandry@google.com>
diff --git a/src/lib.rs b/src/lib.rs
index dd8c2c8..150f76b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -24,9 +24,9 @@
 use crate::device::{enable_networking, shell};
 use crate::package::make_package;
 use crate::sdk::{
-    cargo_path, clang_archiver_path, clang_c_compiler_path, clang_cpp_compiler_path,
-    clang_ranlib_path, clang_resource_dir, rustc_path, rustdoc_path, shared_libraries_path,
-    sysroot_path, target_out_dir, zircon_build_path,
+    cargo_path, clang_archiver_path, clang_c_compiler_path,
+    clang_cpp_compiler_path, clang_ranlib_path, clang_resource_dir, rustc_path, rustdoc_path,
+    shared_libraries_path, sysroot_path, target_out_dir,
 };
 use manifest::Manifest;
 
@@ -335,6 +335,20 @@
     format!("{}-fuchsia", triple_cpu)
 }
 
+pub fn get_vdso_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
+    let vdso_name =
+        if target_options.config.fuchsia_arch == X64 { "user.vdso_x64" } else { "user.vdso_arm64" }
+            .to_string();
+    Ok(target_out_dir(target_options.config)?.join(vdso_name))
+}
+
+pub fn get_user_libc_path(target_options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
+    let libc_name =
+        if target_options.config.fuchsia_arch == X64 { "user.libc_x64" } else { "user.libc_arm64" }
+            .to_string();
+    Ok(target_out_dir(target_options.config)?.join(libc_name))
+}
+
 fn get_rustflags(
     run_cargo_options: &RunCargoOptions,
     target_options: &TargetOptions<'_, '_>,
@@ -365,7 +379,13 @@
             shared_lib_path.to_string_lossy(),
         ),
         format!("-Clink-arg=-L{}", clang_resource_lib.to_string_lossy()),
+        format!("-Clink-arg=-L{}", target_out_dir(target_options.config)?.to_string_lossy()),
+        format!("-Clink-arg=-L{}", get_vdso_path(target_options)?.to_string_lossy()),
         format!("-Clink-arg=--sysroot={}", sysroot_as_path.to_string_lossy()),
+        format!(
+            "-Clink-arg={}/obj/zircon/system/ulib/c/crt1.Scrt1.cc.o",
+            get_user_libc_path(target_options)?.to_string_lossy()
+        ),
         format!("-Lnative={}", shared_libraries_path(target_options)?.to_string_lossy()),
     ];
 
@@ -599,7 +619,6 @@
         .env("RUSTDOC", rustdoc_path()?.to_string_lossy().as_ref())
         .env("RUSTDOCFLAGS", &rustflags)
         .env("FUCHSIA_SHARED_ROOT", shared_libraries_path(target_options)?)
-        .env("ZIRCON_BUILD_ROOT", zircon_build_path(&target_options.config)?)
         .arg(subcommand)
         .args(target_args)
         .args(args);
diff --git a/src/package.rs b/src/package.rs
index 8ef2b19..46fbfd8 100644
--- a/src/package.rs
+++ b/src/package.rs
@@ -3,11 +3,11 @@
 // found in the LICENSE file.
 
 use crate::{
-    get_triple_cpu,
     sdk::{
-        amber_path, clang_base_path, cmc_path, fuchsia_dir, package_manager_path,
-        shared_libraries_path, zircon_build_path, FuchsiaConfig, TargetOptions,
+        amber_path, cmc_path, fuchsia_dir, package_manager_path, shared_libraries_path,
+        FuchsiaConfig, TargetOptions,
     },
+    target_out_dir,
     utils::{strip_binary, target_crate_path},
     RunCargoOptions,
 };
@@ -154,35 +154,22 @@
     if verbose {
         println!("write_manifest_file: target = {:#?}", target);
     }
-    let triple = get_triple_cpu(target_options);
     let mut manifest = File::create(&target)?;
-    let zircon_build = zircon_build_path(&target_options.config)?;
+    let target_out_path = target_out_dir(target_options.config)?;
+    let target_out_path_str = target_out_path.to_string_lossy();
     let shared_lib_path = shared_libraries_path(target_options)?;
     let shared_lib_str = shared_lib_path.to_string_lossy();
-    let libc_path = format!(
-        "{}/user-{}-clang.shlib/obj/system/ulib/c/libc.so",
-        zircon_build.to_string_lossy(),
-        target_options.config.fuchsia_arch
-    );
+    let libc_path = format!("{}/user.libc_x64/libc.so", target_out_path_str);
     let fdio_path = format!("{}/libfdio.so", shared_lib_str);
     let libsyslog_path = format!("{}/libsyslog.so", shared_lib_str);
     let libtraceengine_path = format!("{}/libtrace-engine.so", shared_lib_str);
     let libasync_path = format!("{}/libasync-default.so", shared_lib_str);
-    let libcpp2_path = format!(
-        "{}/lib/{}-unknown-fuchsia/c++/libc++.so.2",
-        clang_base_path()?.to_string_lossy(),
-        triple,
-    );
-    let libcpp1abi_path = format!(
-        "{}/lib/{}-unknown-fuchsia/c++/libc++abi.so.1",
-        clang_base_path()?.to_string_lossy(),
-        triple,
-    );
-    let libunwind_path = format!(
-        "{}/lib/{}-unknown-fuchsia/c++/libunwind.so.1",
-        clang_base_path()?.to_string_lossy(),
-        triple,
-    );
+    let libcpp2_path =
+        format!("{}/obj/build/images/fuchsia.zbi/bootfs/lib/libc++.so.2", target_out_path_str,);
+    let libcpp1abi_path =
+        format!("{}/obj/build/images/fuchsia.zbi/bootfs/lib/libc++abi.so.1", target_out_path_str,);
+    let libunwind_path =
+        format!("{}/obj/build/images/fuchsia.zbi/bootfs/lib/libunwind.so.1", target_out_path_str,);
 
     let additional_libs: Vec<String> = run_cargo_options
         .fargo_manifest
diff --git a/src/sdk.rs b/src/sdk.rs
index e4620ea..6fed023 100644
--- a/src/sdk.rs
+++ b/src/sdk.rs
@@ -118,11 +118,7 @@
 }
 
 pub fn sysroot_path(options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {
-    Ok(shared_libraries_path(&options)?.join("gen").join("build").join("config").join("fuchsia"))
-}
-
-pub fn zircon_build_path(config: &FuchsiaConfig) -> Result<PathBuf, Error> {
-    Ok(PathBuf::from(&config.zircon_build_dir))
+    Ok(target_out_dir(&options.config)?.join("gen/zircon/public/sysroot/cpp"))
 }
 
 pub fn shared_libraries_path(options: &TargetOptions<'_, '_>) -> Result<PathBuf, Error> {