Add logging and fix error related to libunwind
It does not appear that libunwind.so.1 is actually needed for Rust binaries.
Also update the getting started documentation.
Change-Id: If7c61373d34b5d5c6924e21be6fc87f2c1b57ff7
diff --git a/README.md b/README.md
index 4b2f658..73b35d3 100644
--- a/README.md
+++ b/README.md
@@ -13,18 +13,16 @@
-v, --verbose Print verbose output while performing commands
OPTIONS:
- --cmx-path <cmx-path> Path to sandbox file to use when running
- -N, --device-name <device-name>
- Name of device to target, needed if there are multiple devices visible on the network
-
+ -N, --device-name <device-name> Name of device to target, needed if there are multiple devices
+ visible on the network
--manifest-path <manifest-path> Path to Cargo.toml
SUBCOMMANDS:
autotest Auto build and test in Fuchsia device or emulator
build Build binary targeting Fuchsia device or emulator
build-rustc Build rustc targeting Fuchsia
- cargo Run a cargo command for Fuchsia. Use -- to indicate that all following
- arguments should be passed to cargo.
+ cargo Run a cargo command for Fuchsia. Use -- to indicate that all following arguments
+ should be passed to cargo.
check Check binary targeting Fuchsia device or emulator
configure Run a configure script for the cross compilation environment
doc Build a package's documentation
@@ -51,18 +49,9 @@
the first step is to build Fuchsia.
The [Fuchsia Getting
-Started](https://fuchsia.googlesource.com/docs/+/HEAD/getting_started.md)
+Started](https://fuchsia.googlesource.com/fuchsia/+/master/docs/getting_started.md)
instruction are what you need.
-The author most often uses the following steps to update and build Fuchsia in
-preparation for using fargo
-
- ./scripts/fx set-petal garnet
- .jiri_root/bin/jiri update
- ./scripts/fx set x64 out/release-x64 --release
- ./scripts/fx build-zircon
- ./scripts/fx build
-
Once this build is complete, clone and build fargo. For this you will need
a working host Rust installation, most easily installed with [rustup](https://rustup.rs).
diff --git a/src/lib.rs b/src/lib.rs
index 25547d4..6c38440 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -88,7 +88,13 @@
if cmx_path.is_none() {
bail!("Run modes other than normal require a path to a cmx file");
}
- make_package(target_options, &source_path, cmx_path.as_ref().unwrap(), app_name)?
+ make_package(
+ verbose,
+ target_options,
+ &source_path,
+ cmx_path.as_ref().unwrap(),
+ app_name,
+ )?
}
};
@@ -1488,7 +1494,10 @@
.value_of(CMX_PATH)
.expect(&format!("{} is a required parameter of {}", CMX_PATH, MAKE_PACKAGE)),
);
- println!("make package {}", make_package(&target_options, &binary_path, &cmx_path, "app")?);
+ println!(
+ "make package {}",
+ make_package(verbose, &target_options, &binary_path, &cmx_path, "app")?
+ );
return Ok(());
}
diff --git a/src/package.rs b/src/package.rs
index cc06d35..5322345 100644
--- a/src/package.rs
+++ b/src/package.rs
@@ -3,9 +3,8 @@
// found in the LICENSE file.
use crate::{
- get_target_triple,
sdk::{
- amber_path, clang_resource_dir, cmc_path, fuchsia_dir, package_manager_path,
+ amber_path, cmc_path, fuchsia_dir, package_manager_path,
zircon_build_path, FuchsiaConfig, TargetOptions,
},
utils::strip_binary,
@@ -19,7 +18,15 @@
process::Command,
};
-fn validate_cmx_file(fuchsia_config: &FuchsiaConfig, cmx_path: &Path) -> Result<(), Error> {
+fn validate_cmx_file(
+ verbose: bool,
+ fuchsia_config: &FuchsiaConfig,
+ cmx_path: &Path,
+) -> Result<(), Error> {
+ if verbose {
+ println!("validate_cmx_file: cmx_path = {:#?}", cmx_path);
+ }
+
let cmc = cmc_path(fuchsia_config)?;
let output = Command::new(cmc)
@@ -62,6 +69,7 @@
}
fn write_manifest_file(
+ verbose: bool,
target_options: &TargetOptions<'_, '_>,
target: &Path,
binary_path: &Path,
@@ -70,6 +78,9 @@
package_name: &str,
app_name: &str,
) -> Result<(), Error> {
+ if verbose {
+ println!("write_manifest_file: target = {:#?}", target);
+ }
let mut manifest = File::create(&target)?;
let zircon_build = zircon_build_path(&target_options.config)?;
let libc_path = format!(
@@ -82,8 +93,6 @@
zircon_build.to_string_lossy(),
target_options.config.fuchsia_arch
);
- let target_triple = get_target_triple(target_options);
- let clang_resource_lib = clang_resource_dir(&target_triple)?.join(&target_triple).join("lib");
let libsyslog_path = format!(
"{}/user-{}-gcc.shlib/obj/system/ulib/syslog/libsyslog.so",
zircon_build.to_string_lossy(),
@@ -94,7 +103,6 @@
r#"bin/{}={}
lib/ld.so.1={}
lib/libfdio.so={}
-lib/libunwind.so.1={}/libunwind.so.1
lib/libsyslog.so={}
meta/package={}
meta/{}.cmx={}
@@ -103,7 +111,6 @@
binary_path.to_string_lossy(),
libc_path,
fdio_path,
- clang_resource_lib.to_string_lossy(),
libsyslog_path,
package_path.to_string_lossy(),
package_name,
@@ -112,17 +119,22 @@
Ok(())
}
-fn write_package_file(target: &Path, package_name: &str) -> Result<(), Error> {
+fn write_package_file(verbose: bool, target: &Path, package_name: &str) -> Result<(), Error> {
let mut package = File::create(&target)?;
let package_contents = json!({
"name": package_name,
"version": "0"
});
+ if verbose {
+ println!("write_package_file: target = {:#?}", target);
+ println!("write_package_file: package_contents = {:#?}", package_contents);
+ }
writeln!(package, "{}", package_contents.to_string())?;
Ok(())
}
fn pm_build(
+ verbose: bool,
target_options: &TargetOptions<'_, '_>,
manifest_path: &Path,
output_path: &Path,
@@ -131,6 +143,13 @@
let fuchsia_dir = fuchsia_dir()?;
let dev_key_path = fuchsia_dir.join("build/development.key");
+ if verbose {
+ println!("pm_build: package_manager_path = {:#?}", pm);
+ println!("pm_build: fuchsia_dir = {:#?}", fuchsia_dir);
+ println!("pm_build: dev_key_path = {:#?}", dev_key_path);
+ println!("pm_build: manifest_path = {:#?}", manifest_path);
+ println!("pm_build: output_path = {:#?}", output_path);
+ }
let output = Command::new(pm)
.arg("-k")
.arg(dev_key_path)
@@ -153,10 +172,15 @@
}
fn pm_archive(
+ verbose: bool,
target_options: &TargetOptions<'_, '_>,
output_path: &Path,
manifest_path: &Path,
) -> Result<(), Error> {
+ if verbose {
+ println!("pm_archive: output_path = {:#?}", output_path);
+ println!("pm_archive: manifest_path = {:#?}", manifest_path);
+ }
let pm = package_manager_path(target_options.config)?;
let output = Command::new(pm)
@@ -166,7 +190,7 @@
.arg(&manifest_path)
.arg("archive")
.output()
- .context("Running `cmc` to format cmx file")?;
+ .context("Running `pm_archive` to build an archive")?;
if !output.status.success() {
bail!("pm returned error: {}", String::from_utf8_lossy(&output.stderr));
@@ -175,9 +199,17 @@
Ok(())
}
-fn pm_publish(target_options: &TargetOptions<'_, '_>, output_path: &Path) -> Result<(), Error> {
+fn pm_publish(
+ verbose: bool,
+ target_options: &TargetOptions<'_, '_>,
+ output_path: &Path,
+) -> Result<(), Error> {
let pm = package_manager_path(target_options.config)?;
let tuf_root = amber_path(target_options.config)?;
+ if verbose {
+ println!("pm_publish: output_path = {:#?}", output_path);
+ println!("pm_publish: tuf_root = {:#?}", tuf_root);
+ }
let output = Command::new(pm)
.arg("publish")
.arg("-a")
@@ -188,7 +220,7 @@
.arg("-vt")
.arg("-v")
.output()
- .context("Running `cmc` to format cmx file")?;
+ .context("Running `publish` to publish package")?;
if !output.status.success() {
bail!("pm returned error: {}", String::from_utf8_lossy(&output.stderr));
@@ -198,6 +230,7 @@
}
pub fn make_package(
+ verbose: bool,
target_options: &TargetOptions<'_, '_>,
binary_path: &Path,
cmx_path: &Path,
@@ -211,15 +244,22 @@
.to_string_lossy()
.to_string();
package_name.push_str("_fargo");
+ if verbose {
+ println!("make_package: package_name = {:#?}", package_name);
+ }
let output_path = binary_parent.join(&package_name);
+ if verbose {
+ println!("make_package: output_path = {:#?}", output_path);
+ }
create_dir_all(&output_path).context("create_dir_all failed")?;
let stripped_binary_path = strip_binary(binary_path)?;
- validate_cmx_file(&target_options.config, cmx_path)?;
+ validate_cmx_file(verbose, &target_options.config, cmx_path)?;
let formatted_path = format_cmx_file(&target_options.config, cmx_path)?;
let package_path = PathBuf::from("/tmp/package");
- write_package_file(&package_path, &package_name)?;
+ write_package_file(verbose, &package_path, &package_name)?;
let manifest_path = PathBuf::from("/tmp/manifest");
write_manifest_file(
+ verbose,
&target_options,
&manifest_path,
&stripped_binary_path,
@@ -228,9 +268,10 @@
&package_name,
app_name,
)?;
- pm_build(&target_options, &manifest_path, &output_path).context("pm_build failed")?;
- pm_archive(&target_options, &output_path, &manifest_path).context("pm_archive failed")?;
- pm_publish(&target_options, &output_path.join(format!("{}-0.far", package_name)))
+ pm_build(verbose, &target_options, &manifest_path, &output_path).context("pm_build failed")?;
+ pm_archive(verbose, &target_options, &output_path, &manifest_path)
+ .context("pm_archive failed")?;
+ pm_publish(verbose, &target_options, &output_path.join(format!("{}-0.far", package_name)))
.context("pm_publish failed")?;
Ok(format!("fuchsia-pkg://fuchsia.com/{}#meta/{}.cmx", package_name, package_name))
}