[Pkg-rust-maintainers] Bug#858153: cargo: stage0 build fails

peter green plugwash at p10link.net
Wed Mar 22 12:50:52 UTC 2017


tags 858153 +patch
thanks

On 19/03/17 00:45, peter green wrote:
> It seems that trying to do a "stage0" build of cargo no longer works.
After a lot of hacking I managed to get a successful stage0 build in raspbian stretch. I attach the patch I used to do so, I have not tested said patch in Debian.


-------------- next part --------------
diff -Nru cargo-0.15.0~dev/debian/bootstrap.py cargo-0.15.0~dev/debian/bootstrap.py
--- cargo-0.15.0~dev/debian/bootstrap.py	2016-11-25 23:11:55.000000000 +0000
+++ cargo-0.15.0~dev/debian/bootstrap.py	2017-03-20 23:06:07.000000000 +0000
@@ -471,7 +471,8 @@
                         return Semver(str(int(major) + 1) + '.0.0')
                     else:
                         # ^0.0 means >=0.0.0 and <0.1.0
-                        return Semver(major + '.' + str(int(minor) + 1) + '.0')
+                        # HACK: change limit to +3 to work around "url" failure
+                        return Semver(major + '.' + str(int(minor) + 3) + '.0')
                 else:
                     # ^0.0.1 means >=0.0.1 and <0.0.2
                     # ^0.1.2 means >=0.1.2 and <0.2.0
@@ -646,18 +647,24 @@
         #dbg(' env: %s' % env)
         #dbg(' cwd: %s' % self._cwd)
         envstr = ''
+        env['DEP_OPENSSL_VERSION'] = '102'
+        envsanitised = {}
         for k, v in env.iteritems():
             envstr += ' %s="%s"' % (k, v)
+            envsanitised[k] = str(v)
         if self._cwd is not None:
             dbg('cd %s && %s %s' % (self._cwd, envstr, ' '.join(cmd)))
         else:
             dbg('%s %s' % (envstr, ' '.join(cmd)))
 
-        proc = subprocess.Popen(cmd, env=env,
+        print('about to call subprocess.popen envsanitised='+repr(envsanitised))
+        sys.stdout.flush()
+        proc = subprocess.Popen(cmd, env=envsanitised,
                                 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                                 cwd=self._cwd)
         out, err = proc.communicate()
-
+        print('subprocess.communicate complete')
+        sys.stdout.flush()
         for lo in out.split('\n'):
             if len(lo) > 0:
                 self._stdout.append(lo)
@@ -803,6 +810,7 @@
                     continue
 
                 svr = SemverRange(d['req'])
+                print('d[''req'']: '+repr(d['req']))
                 print ''
                 deps = []
                 dbg('Looking up info for %s %s' % (d['name'], str(svr)))
@@ -1233,15 +1241,21 @@
         for l in lines:
             dep_infos.append(json.loads(l))
 
+    print('svr: '+repr(svr))
     passed = {}
     for info in dep_infos:
+        print('info: '+repr(info))
         if 'vers' not in info:
             continue
         sv = Semver(info['vers'])
+	print('sv: '+repr(sv))
         if svr.compare(sv):
             passed[sv] = info
 
     keys = sorted(passed.iterkeys())
+    print('keys: '+repr(keys))
+    sys.stdout.flush()
+    
     best_match = keys.pop()
     dbg('best match is %s-%s' % (name, best_match))
     best_info = passed[best_match]
diff -Nru cargo-0.15.0~dev/debian/cargo-vendor-pack.py cargo-0.15.0~dev/debian/cargo-vendor-pack.py
--- cargo-0.15.0~dev/debian/cargo-vendor-pack.py	2016-11-25 23:11:55.000000000 +0000
+++ cargo-0.15.0~dev/debian/cargo-vendor-pack.py	2017-03-20 23:06:07.000000000 +0000
@@ -97,7 +97,7 @@
 
   indexdict = OrderedDict()
   for crate in os.listdir(depsdir):
-    if os.path.isdir(os.path.join(depsdir, crate)) and not crate.startswith('.'):
+    if os.path.isdir(os.path.join(depsdir, crate)) and (not crate.startswith('.')) and (crate.find('-') >= 0):
       (name, ver) = string.rsplit(crate, '-', 1)
       print("Found %s ver. %s (at %s)" % (name, ver, os.path.join(depsdir, crate)))
       destdir=(os.path.join(cachedir, name, ver))
diff -Nru cargo-0.15.0~dev/debian/changelog cargo-0.15.0~dev/debian/changelog
--- cargo-0.15.0~dev/debian/changelog	2016-11-25 23:30:03.000000000 +0000
+++ cargo-0.15.0~dev/debian/changelog	2017-03-20 23:06:07.000000000 +0000
@@ -1,3 +1,21 @@
+cargo (0.15.0~dev-1+rpi1) stretch-staging; urgency=medium
+
+  * Hack around bootsrap failure to find crates-io by copying files
+  * Add more debug info to bootstrap script
+  * Make bootstrap script less strict on versioning
+  * Fix clean target
+  * Make bootstrap script ensure environment is strings
+  * Add bootstrapping patch for upstream source, applied only during bootstrapping
+    + comment out  fs::remove_dir_all(env::var("OUT_DIR").unwrap()); in deps/libgit2-sys-0.6.2/build.rs , it seems to destroy the whole "deps" tree when invoked from the bootstrap script.
+    + Remove optional flag from miniz-sys dependency in /cargo-0.15.0~dev.new/deps/flate2-0.2.14/Cargo.toml
+    + Move libc dependency in deps/net2-0.2.26/Cargo.toml from unix section to general section.
+    + Move openssl dependency in Cargo.toml from unix section to general section.
+  * Force DEP_OPENSSL_VERSION to 102 during bootstrap.
+  * Use seperate cargo-vendor-pack invocations for bootstrap and main build
+  * Make cargo-vendor-pack ignore directories without - in their name
+
+ -- Peter Michael Green <plugwash at raspbian.org>  Mon, 20 Mar 2017 23:06:07 +0000
+
 cargo (0.15.0~dev-1) unstable; urgency=medium
 
   * New upstream snapshot (git 1877f59d6b2cb057f7ef6c6b34b926fd96a683c1)
diff -Nru cargo-0.15.0~dev/debian/patches/bootstrap-hacks.patch cargo-0.15.0~dev/debian/patches/bootstrap-hacks.patch
--- cargo-0.15.0~dev/debian/patches/bootstrap-hacks.patch	1970-01-01 00:00:00.000000000 +0000
+++ cargo-0.15.0~dev/debian/patches/bootstrap-hacks.patch	2017-03-20 23:06:07.000000000 +0000
@@ -0,0 +1,69 @@
+Description: bootstrap hacks
+ Patch for any bootstrapping related hacks made to "upstream" source as part of my attempts to bootstrap rust for raspbian.
+   * comment out  fs::remove_dir_all(env::var("OUT_DIR").unwrap()); in deps/libgit2-sys-0.6.2/build.rs , it seems to destroy the whole "deps" tree when invoked from the bootstrap script.
+   * Remove optional flag from miniz-sys dependency in /cargo-0.15.0~dev.new/deps/flate2-0.2.14/Cargo.toml
+   * Move libc dependency in deps/net2-0.2.26/Cargo.toml from unix section to general section.
+   * Move openssl dependency in Cargo.toml from unix section to general section.
+Author: Peter Michael Green <plugwash at raspbian.org>
+
+Index: cargo-0.15.0~dev.new/deps/libgit2-sys-0.6.2/build.rs
+===================================================================
+--- cargo-0.15.0~dev.new.orig/deps/libgit2-sys-0.6.2/build.rs
++++ cargo-0.15.0~dev.new/deps/libgit2-sys-0.6.2/build.rs
+@@ -111,7 +111,7 @@ fn main() {
+         cfg.define("CURL", "OFF");
+     }
+ 
+-    let _ = fs::remove_dir_all(env::var("OUT_DIR").unwrap());
++    // let _ = fs::remove_dir_all(env::var("OUT_DIR").unwrap());
+     t!(fs::create_dir_all(env::var("OUT_DIR").unwrap()));
+ 
+     let dst = cfg.define("BUILD_SHARED_LIBS", "OFF")
+Index: cargo-0.15.0~dev.new/deps/flate2-0.2.14/Cargo.toml
+===================================================================
+--- cargo-0.15.0~dev.new.orig/deps/flate2-0.2.14/Cargo.toml
++++ cargo-0.15.0~dev.new/deps/flate2-0.2.14/Cargo.toml
+@@ -17,7 +17,7 @@ streams.
+ 
+ [dependencies]
+ libc = "0.2"
+-miniz-sys = { path = "miniz-sys", version = "0.1.7", optional = true }
++miniz-sys = { path = "miniz-sys", version = "0.1.7" }
+ libz-sys = { version = "1.0", optional = true }
+ 
+ [dev-dependencies]
+Index: cargo-0.15.0~dev.new/deps/net2-0.2.26/Cargo.toml
+===================================================================
+--- cargo-0.15.0~dev.new.orig/deps/net2-0.2.26/Cargo.toml
++++ cargo-0.15.0~dev.new/deps/net2-0.2.26/Cargo.toml
+@@ -16,9 +16,6 @@ ws2_32-sys = "0.2"
+ winapi = "0.2"
+ kernel32-sys = "0.2"
+ 
+-[target."cfg(unix)".dependencies]
+-libc = "0.2.14"
+-
+ # Compat with older Cargo versions temporarily
+ [target.x86_64-unknown-linux-gnu.dependencies]
+ libc = "0.2.14"
+@@ -31,6 +28,7 @@ libc = "0.2.14"
+ 
+ [dependencies]
+ cfg-if = "0.1"
++libc = "0.2.14"
+ 
+ [features]
+ nightly = []
+Index: cargo-0.15.0~dev.new/Cargo.toml
+===================================================================
+--- cargo-0.15.0~dev.new.orig/Cargo.toml
++++ cargo-0.15.0~dev.new/Cargo.toml
+@@ -45,8 +45,6 @@ term = "0.4.4"
+ toml = "0.2"
+ url = "1.1"
+ #winapi = "0.2"
+-
+-[target.'cfg(unix)'.dependencies]
+ openssl = "0.9"
+ 
+ #[dev-dependencies]
diff -Nru cargo-0.15.0~dev/debian/rules cargo-0.15.0~dev/debian/rules
--- cargo-0.15.0~dev/debian/rules	2016-11-25 23:30:03.000000000 +0000
+++ cargo-0.15.0~dev/debian/rules	2017-03-20 23:06:07.000000000 +0000
@@ -25,11 +25,17 @@
 
 override_dh_auto_configure:
 	cp -a $(CURDIR)/Cargo.lock $(CURDIR)/.Cargo.lock.orig
-	# Prepare a fake registry by packing all deps
-	./debian/cargo-vendor-pack.py
 
 override_dh_auto_build:
 ifneq ($(filter stage0,$(DEB_BUILD_PROFILES)),)
+	#workaround failure to find crates-io in bootstrap script
+	cp -a src/crates-io deps/crates-io-0.4.0
+	mkdir deps/crates-io-0.4.0/src
+	mv deps/crates-io-0.4.0/*.rs deps/crates-io-0.4.0/src
+	# Apply bootstrapping hacks to upstream source
+	patch -p1 < debian/patches/bootstrap-hacks.patch
+	# Prepare a fake registry by packing all deps
+	./debian/cargo-vendor-pack.py
 	# Bootstrap cargo stage0
 	./debian/bootstrap.py \
 		--no-clean \
@@ -41,11 +47,20 @@
 		--target-dir $(DEPSDIR)/ \
 		--host=$(DEB_HOST_RUST_TYPE) \
 		--target=$(DEB_TARGET_RUST_TYPE)
+	# Remove bootstrapping hacks again
+	patch -p1 -R < debian/patches/bootstrap-hacks.patch
+	#cleanup our crates-io hack
+	rm -rf deps/crates-io-0.4.0
+	rm -rf $(VENDORDIR)
+	# Prepare a fake registry by packing all deps
+	./debian/cargo-vendor-pack.py
 	# Workaround for https://github.com/rust-lang/cargo/issues/1423
 	mv $(DEPSDIR) $(CURDIR)/.deps
 	ln -s `find $(CURDIR)/.deps -name 'cargo-*' -type f -executable` $(CURDIR)/cargo-stage0
 else
 	ln -s `which cargo` $(CURDIR)/cargo-stage0
+	# Prepare a fake registry by packing all deps
+	./debian/cargo-vendor-pack.py
 	# Workaround for https://github.com/rust-lang/cargo/issues/1423
 	mv $(DEPSDIR) $(CURDIR)/.deps
 endif
@@ -82,6 +97,16 @@
 			$(CURDIR)/cargo-stage0 \
 			$(CARGO_HOME) \
 			$(VENDORDIR)
+	#cleanup our crates-io hack
+	rm -rf deps/crates-io-0.4.0
+	#cleanup leftover files/dirs
+	rm -f config.tmp deps/aho_corasick_dot-0_5_3 deps/docopt_wordlist-0_6_86
+	rm -rf deps/lib deps/build deps/include
+	find . -name '*.a' -delete
+	find . -name '*.c.o' -delete
+	find . -name '*.bin' -delete
+	find . -name '*.d' -delete
+
 
 override_dh_auto_install:
 	# We pick stuff directly from target/


More information about the Pkg-rust-maintainers mailing list