Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd a Cargo-based build system to eventually replace make #31123
Conversation
alexcrichton
assigned
brson
Jan 22, 2016
This comment has been minimized.
This comment has been minimized.
|
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Hero mode omg |
This comment has been minimized.
This comment has been minimized.
|
In terms of review, I've tried to split things up in as bite-sized chunks as possible, and I'll avoid rebasing for awhile so the commit comments are preserved |
This comment has been minimized.
This comment has been minimized.
|
Yesss |
This comment has been minimized.
This comment has been minimized.
|
Hold the phone. |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton does it again! |
Gankro
added
T-tools
relnotes
labels
Jan 22, 2016
This comment has been minimized.
This comment has been minimized.
|
Is the python bit optional? As in, if we already had a recent enough rust/cargo nightly, could we just directly build the Rust bootstrap and go from there? |
frewsxcv
reviewed
Jan 22, 2016
| import tarfile | ||
|
|
||
| def get(url, path, quiet=False): | ||
| if quiet: |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jan 23, 2016
Author
Member
Oh this is actually intended (albeit kinda weirdly) where quiet means "just print what you're downloading" and not quiet means "print the command we're running"
frewsxcv
reviewed
Jan 22, 2016
| run(["curl", "-o", path, url], quiet=quiet) | ||
|
|
||
| def unpack(tarball, dst, quiet=False, filter=None): | ||
| if quiet: |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jan 23, 2016
Author
Member
ah same as above where quiet means "less status messages" and not quiet means "lots of status messages"
I'll update this variable name though
frewsxcv
reviewed
Jan 22, 2016
| fname = os.path.basename(tarball).replace(".tar.gz", "") | ||
| with contextlib.closing(tarfile.open(tarball)) as tar: | ||
| for p in tar.getnames(): | ||
| if not "/" in p: |
This comment has been minimized.
This comment has been minimized.
frewsxcv
reviewed
Jan 22, 2016
| else: | ||
| run(["curl", "-o", path, url], quiet=quiet) | ||
|
|
||
| def unpack(tarball, dst, quiet=False, filter=None): |
This comment has been minimized.
This comment has been minimized.
frewsxcv
Jan 22, 2016
Member
Not a huge deal, but FYI, filter here is shadowing the global filter function
frewsxcv
reviewed
Jan 22, 2016
| name = p.replace(fname + "/", "", 1) | ||
| if filter is not None and not name.startswith(filter): | ||
| continue | ||
| else: |
This comment has been minimized.
This comment has been minimized.
frewsxcv
reviewed
Jan 22, 2016
| return os.path.join(self.build_dir, self.build, "stage0") | ||
|
|
||
| def get_toml(self, key): | ||
| for line in iter(self.config_toml.splitlines()): |
This comment has been minimized.
This comment has been minimized.
frewsxcv
Jan 22, 2016
Member
I don't think iter(..) is necessary here (nor a few lines down), but I could be wrong
frewsxcv
reviewed
Jan 22, 2016
| nightlies = os.path.join(self.rust_root, "src/nightlies.txt") | ||
| rustc, cargo = open(nightlies, 'r').read().split("\n")[:2] | ||
| assert(rustc.startswith("rustc: ")) | ||
| assert(cargo.startswith("cargo: ")) |
This comment has been minimized.
This comment has been minimized.
frewsxcv
reviewed
Jan 22, 2016
|
|
||
| def parse_nightly_dates(self): | ||
| nightlies = os.path.join(self.rust_root, "src/nightlies.txt") | ||
| rustc, cargo = open(nightlies, 'r').read().split("\n")[:2] |
This comment has been minimized.
This comment has been minimized.
frewsxcv
Jan 22, 2016
Member
Might be good to use a context manager here (with open(..):) so the file gets properly closed
frewsxcv
reviewed
Jan 22, 2016
| proc = subprocess.Popen(args, env = env) | ||
| ret = proc.wait() | ||
| if ret != 0: | ||
| exit(ret) |
This comment has been minimized.
This comment has been minimized.
frewsxcv
Jan 22, 2016
Member
Use sys.exit instead of exit. The latter is something unrelated and misleading
frewsxcv
reviewed
Jan 22, 2016
| raise Exception("unknown OS type: " + ostype) | ||
|
|
||
| if (cputype == 'i386' or cputype == 'i486' or cputype == 'i686' or | ||
| cputype == 'i786' or cputype == 'x86'): |
This comment has been minimized.
This comment has been minimized.
frewsxcv
Jan 22, 2016
Member
This could also be written:
if cputype in {'i386', 'i486', 'i686', 'i786', 'x86'}:{a, b, c} is set notation fyi
frewsxcv
reviewed
Jan 22, 2016
| rb.verbose = args.verbose | ||
|
|
||
| try: | ||
| rb.config_toml = open(args.config or 'config.toml').read() |
This comment has been minimized.
This comment has been minimized.
frewsxcv
reviewed
Jan 22, 2016
| except: | ||
| pass | ||
| try: | ||
| rb.config_mk = open('config.mk').read() |
This comment has been minimized.
This comment has been minimized.
frewsxcv
reviewed
Jan 23, 2016
| else | ||
| RUSTFLAGS_rustc_back := --cfg disable_jemalloc | ||
| endif |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There's some discussion here about this as well, but I wouldn't necessarily want it to be a prerequisite to build Rust that you have Rust installed just yet. Maybe down the road we can expect that (I think gcc requires this, right?). That being said I would love to remove even the python script (as @frewsxcv has discovered I'm awful at writing python) and just have pure Rust from the get-go. For now though we require Python because of the LLVM build anyway, and I tried to keep the Python as tiny as possible. Hopefully we can either minimize the python over time (e.g. get it even smaller than it is today) or possibly even rewrite it in Rust as you mentioned and just assume that rustc is available. |
This comment has been minimized.
This comment has been minimized.
|
I've started keeping a tentative list of items left-to-implement at the top of this PR as well. I plan on explicitly not implementing them here but rather opening follow-up tracking issues for them. |
lndbrg
reviewed
Jan 23, 2016
| if code != 0: | ||
| if not verbose: | ||
| print("failed to run: " + ' '.join(args)) | ||
| raise Exception("failed to run command") |
This comment has been minimized.
This comment has been minimized.
lndbrg
reviewed
Jan 23, 2016
| cputype = 'x86_64' | ||
| ostype = 'pc-windows-gnu' | ||
| else: | ||
| raise Exception("unknown OS type: " + ostype) |
This comment has been minimized.
This comment has been minimized.
lndbrg
reviewed
Jan 23, 2016
| elif cputype in {'amd64', 'x86_64', 'x86-64', 'x64'}: | ||
| cputype = 'x86_64' | ||
| else: | ||
| raise Exception("unknown cpu type: " + cputype) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Aside: How does one use this build system? I tried
|
This comment has been minimized.
This comment has been minimized.
|
I'm gonna rebase this to get rid of the merge and |
alexcrichton
added some commits
Nov 19, 2015
alexcrichton
force-pushed the
alexcrichton:who-doesnt-want-two-build-systems
branch
from
96bf1b9
to
1bd4a65
Feb 11, 2016
This comment has been minimized.
This comment has been minimized.
alexcrichton
added some commits
Jan 21, 2016
alexcrichton
force-pushed the
alexcrichton:who-doesnt-want-two-build-systems
branch
from
1bd4a65
to
55dd595
Feb 11, 2016
This comment has been minimized.
This comment has been minimized.
eddyb
referenced this pull request
Feb 11, 2016
Closed
Lint against calling .clone() on an otherwise copyable value. #27266
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Feb 11, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry On Thu, Feb 11, 2016 at 2:16 PM, bors notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Feb 12, 2016
This comment has been minimized.
This comment has been minimized.
bors
merged commit 55dd595
into
rust-lang:master
Feb 12, 2016
This was referenced Feb 12, 2016
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton commentedJan 22, 2016
This series of commits adds the initial implementation of a new build system for
the compiler and standard library based on Cargo. The high-level architecture
now looks like:
./configurescript is run with--enable-rustbuildand other standardconfiguration options.
Makefileis generate which proxies commands to the new build system.downloading both a Rust and Cargo nightly. This initial script also manages
building the build system itself (which is written in Rust).
bootstrap, architects how tocall
cargoand manages building all native libraries and such.One might reasonably ask "why rewrite the build system?", which is a good
question! The Rust project has used Makefiles for as long as I can remember at
least, and while ugly and difficult to use are undeniably robust as they contain
years worth of tweaking and tuning for working on as many platforms in as many
situation as possible. The rationale behind this PR, however is:
planet. This means that contributions to the build system are almost
nonexistent, and furthermore if a build system change is needed it's
incredibly difficult to figure out how to do so. This hindrance prevents us
from doing some "perhaps fancier" things we may wish to do in make.
everywhere. For example the recently-introduced MSVC target is quite unlikely
to have
makeinstalled by default (e.g. it requires building inside of anMSYS2 shell currently). Conversely, the portability of make comes at a cost of
crazy and weird hacks to work around all sorts of versions of software
everywhere, especially when it comes to the configure script and makefiles.
By rewriting this logic in one of the most robust platforms there is, Rust,
we get to assuage all of these worries for free!
and compiler don't use it. This means that they cannot benefit easily from the
crates.io ecosystem, nor can the ecosystem benefit from a standard way to
build this repository itself. Moving to Cargo should help assuage both of
these needs. This has the added benefit of making the compiler more
approachable for newbies as working on the compiler will just happen to be
working on a large Cargo project, all the same standard tools and tricks will
apply.
example around cross compiling, compiling on new OSes, etc. Pushing this logic
into standard crates (like
gcc) enables the community to immediately benefitfrom new build logic.
Despite these benefits, it's going to be a long road to actually replace our
current build system. This PR is just the beginning and doesn't implement the
full suite of functionality as the current one, but there are many more to
follow! The current implementation strategy hopes to look like:
contributed to. This will not be used just yet in terms of gating new commits
to the repo.
system, start setting up CI for both build systems.
keep the old one around.
Alright, so with all that out of the way, here's some more info on this PR
itself. The inital build system here is contained in the
src/bootstrapdirectory and just adds the necessary minimum bits to bootstrap the compiler
itself. There is currently no support for building documentation, running tests,
or installing, but the implemented support is:
cmakeinstead of./configure+make. The LLVMproject is removing their autotools build system, so we'd have to make this
transition eventually anyway.
cmakeas well (for the same rationale as above).Cargo.tomlto map out the dependency graph to all crates, and alsoadding
build.rsfiles where appropriate. For examplealloc_jemallochas ascript to build jemalloc,
flatehas a script to buildminiz.c,stdwillbuild
libbacktrace, etc.cargoto build the standard distribution,following the normal bootstrapping process. This also tracks dependencies
between steps to ensure cross-compilation targets happen as well.
config.tomlfile,so support is implemented for this. The most likely vector of configuration
for now, however, is likely through
config.mk(what./configureemits), sothe build system currently parses this information.
There's still quite a few steps left to do, and I'll open up some follow-up
issues (as well as a tracking issue) for this migration, but hopefully this is a
great start to get going! This PR is currently tested on all the
Windows/Linux/OSX triples for x86_64 and x86, but more portability is always
welcome!
Future functionality left to implement
makebuild systemmake install- like testing this is also quite massive