Repository: spack/spack

Issue:
Failed to build rust due to ar issue
I failed to build rust because that the unexistingn archiever `/lustre/home/rpm/spack/lib/spack/env/gcc/ar` was evoked during build. 

### Expected Result

Rust build succeeded.

### Actual Result

Rust build failed.

### Steps to reproduce the issue

```console
$ spack clean
$ rm -rf $SPACK_ROOT/var/spack/cache/rust/*
$ spack install rust
...
==> Error: ProcessError: Command exited with status 2:
    'make' '-j6'

1 error found in build log:
     115    couldn't find required command: "/lustre/home/rpm/spack/lib/spack/env/gcc/ar"
     116    
     117    ', src/bootstrap/sanity.rs:65:12
     118    note: Run with `RUST_BACKTRACE=1` for a backtrace.
     119    failed to run: /lustre/home/rpm/spack/var/spack/stage/rust-1.23.0-zskm6as22m5lv2ldwojyeknjwa5thrni/rus
            t/build/bootstrap/debug/bootstrap build
     120    Build completed unsuccessfully in 0:05:12
  >> 121    make: *** [all] Error 1

See build log for details:
  /lustre/home/rpm/spack/var/spack/stage/rust-1.23.0-zskm6as22m5lv2ldwojyeknjwa5thrni/rust/spack-build.out
```

### Information on your system

I am using CentOS 7. Both `rust` and `cargo` have been bump to the latest versions, 1.23.0 and 0.24.0 separately. No other relevant modificiation has been made to Spack, I think. Full build logs and envs can be found attached.

[spack-build.env.txt](https://github.com/spack/spack/files/1695320/spack-build.env.txt)
[spack-build.out.txt](https://github.com/spack/spack/files/1695321/spack-build.out.txt)



Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/rust/package.py b/var/spack/repos/builtin/packages/rust/package.py
--- a/var/spack/repos/builtin/packages/rust/package.py
+++ b/var/spack/repos/builtin/packages/rust/package.py
@@ -4,12 +4,6 @@
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
 
 from spack import *
-import os
-
-
-def get_submodules():
-    git = which('git')
-    git('submodule', 'update', '--init', '--recursive')
 
 
 class Rust(Package):
@@ -18,12 +12,7 @@ class Rust(Package):
     homepage = "http://www.rust-lang.org"
     git      = "https://github.com/rust-lang/rust.git"
 
-    version('1.8.0', tag='1.8.0')
-
-    resource(name='cargo',
-             git="https://github.com/rust-lang/cargo.git",
-             tag='0.10.0',
-             destination='cargo')
+    version('1.30.1', tag='1.30.1')
 
     extendable = True
 
@@ -32,39 +21,36 @@ class Rust(Package):
     depends_on("curl")
     depends_on("git")
     depends_on("cmake")
+    depends_on("binutils")
     depends_on("python@:2.8")
 
     # Cargo
     depends_on("openssl")
 
-    def install(self, spec, prefix):
-        configure('--prefix=%s' % prefix,
-                  '--llvm-root=' + spec['llvm'].prefix)
+    phases = ['configure', 'install']
+
+    def configure(self, spec, prefix):
+        configure_args = [
+          '--prefix=%s' % prefix,
+          '--llvm-root=' + spec['llvm'].prefix,
+          # Workaround for "FileCheck does not exist" error
+          '--disable-codegen-tests',
+          # Includes Cargo in the build
+          # https://github.com/rust-lang/cargo/issues/3772#issuecomment-283109482
+          '--enable-extended',
+          # Prevent build from writing bash completion into system path
+          '--sysconfdir=%s' % join_path(prefix, 'etc/')
+          ]
+
+        configure(*configure_args)
+
+        # Build system defaults to searching in the same path as Spack's
+        # compiler wrappers which causes the build to fail
+        filter_file(
+            '#ar = "ar"',
+            'ar = "%s"' % join_path(spec['binutils'].prefix.bin, 'ar'),
+            'config.toml')
 
+    def install(self, spec, prefix):
         make()
         make("install")
-
-        # Install cargo, rust package manager
-        with working_dir(os.path.join('cargo', 'cargo')):
-            get_submodules()
-            configure('--prefix=' + prefix,
-                      '--local-rust-root=' + prefix)
-
-            make()
-            make("install")
-
-    def setup_dependent_package(self, module, dependent_spec):
-        """
-        Called before python modules' install() methods.
-
-        In most cases, extensions will only need to have one or two lines::
-
-            cargo('build')
-            cargo('install', '--root', prefix)
-
-        or
-
-            cargo('install', '--root', prefix)
-        """
-        # Rust extension builds can have a global cargo executable function
-        module.cargo = Executable(join_path(self.spec.prefix.bin, 'cargo'))


Test patch: