Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gcc and binutils packages #60

Conversation

cosmicexplorer
Copy link
Contributor

@cosmicexplorer cosmicexplorer commented Mar 21, 2018

gcc (like clang) is being provided for both OSX and Linux. binutils does not support OSX (and I've tried to change that, believe me), so the linker will stay an unsolved problem for now. The scripts for all 3 of these tools will mkdir -p the appropriate output directories and copy the packaged archive over to build-support/bin/${tool}/${arch}/${version}/${tool}.tar.gz (and also, all are being provided as tgz archives -- BinaryTool is great!).

The packages produced by these scripts have been used to successfully compile and link code in an extremely bare Linux environment. The same level of testing has not been done with OSX, but I have done my best to make as much of the script as cross-platform as possible so the only feature gaps are the ones in the software we're depending on.

Be forewarned that gcc can take literal days to build unless you dial up the parallelism (using MAKE_JOBS), but that you can't do that on OSX due to race conditions (unclear why, but it has always failed when I've tried).

Let me know if there's a ton more work to be done here or if these look alright. Obviously these packages are big, and they are also hard to slim down -- that's not saying it's impossible.

Also, here is my pants PR which consumes these subsystems. Please let me know if there are any challenges to getting either of these PRs merged that I haven't considered. Thanks!

I know the history is all screwy, github stopped letting me upload files > 100MB to this repo (even though I'd successfully uploaded them before e.g. clang?) and I'm not sure why. I can spend some effort making the version history cleaner to merge if necessary, especially for a repo with huge binaries where everything can be slow sometimes.

Copy link
Contributor

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for putting this together :) A few pretty minor comments

I think @stuhood was saying we're going to stop checking in binaries at all, which hopefully should make your pushing large files problem go away...

mkdir -p "$BINUTILS_BUILD_TMP_DIR"
pushd "$BINUTILS_BUILD_TMP_DIR" # root -> $BINUTILS_BUILD_TMP_DIR

curl -L -v -O "$BINUTILS_RELEASE_URL"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throw in a --fail, and throughout the PR (which I really, really wish was the default)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@@ -0,0 +1,160 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to re-use the same script for 5.0.1 and 6.0.0, given the differences seem to be:

  1. Actual version numbers
  2. A 'final' being present or absent in a string
  3. Extracting two extra directories

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, just wasn't sure if that was something people would find useful. This works for clang 5.0.1 and 6.0.0 now using e.g. ./build-clang.sh osx 5.0.1 (or it worked when I last tried running it, will focus on correctness later today).

--build="x86_64-apple-darwin${_osx_uname_release}"
--host="x86_64-apple-darwin${_osx_uname_release}"
--target="x86_64-apple-darwin${_osx_uname_release}"
--with-system-zlib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is statically linking zlib an option? Fewer system deps are better imo...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that was ripped from the homebrew recipe without further thought. I have since tried investigating how difficult it would be to build all of these from the CentOS docker image, which changed these again (this file is now build-gcc.sh).

## Some functions, despite bash making it unnecessarily hard to use them.

# Check if a directory exists, and error out or return its absolute
# path. Passing -f allows testing a file as well.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-e just tests "exists" - is -d vs -f actually a distinction you care about?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! And random meaningless arguments in shell scripts get confusing pretty fast, so a great point to note. See get_existing_absolute_path in utils.bash for what this function ended up turning into.

@cosmicexplorer
Copy link
Contributor Author

Changed everything a lot, now we have build-{clang,binutils,cmake,gcc}.sh which can be invoked with a target platform (osx or linux) and a release version (e.g. ./build-gcc.sh osx 7.3.0). This is partially inspired by @illicitonion's comment above about duplicating whole scripts for different versions, and partially because it would be extremely nice if we could compile everything from our trusty docker container (if we can't, then we have lost nothing whatsoever).

Each new script (and functions within those scripts) echoes some single distinct "product" to stdout upon completion, and tries to work within its own subdirectory whenever possible. This idiom may not be necessary but seemed to be make this type of script easier to write and follow.

The idea with this is that ./populate-native-toolchain.sh can be edited and then invoked to fill out the entire directory structure for these scripts. Like anything with enough shell scripts, one begins to wonder whether another language is necessary -- I don't think we're there yet, but I could be wrong. If you run ./populate-native-toolchain.sh you'll find that it fails (that or I'm being rate-limited by the gcc mirror). I haven't verified that all the combinations work, and will do that ASAP -- just want to know whether this seems like a potentially-useful approach for this PR.

Copy link
Contributor

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is genuinely some of the best crafted bash I've ever seen. Kudos!

I haven't run this, but I'm happy with it assuming it runs. Handing over to @stuhood for how things should look in a no-binaries-committed world :)


## Interpret arguments and execute build.

# $1 =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete?

local -r path_arg="$1"
# -f is an "illegal option" for OSX readlink, so this may have e.g. `/../`
# within it.
local -r abs_path="$(pwd)/${path_arg}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Check that path_arg is relative - if it's absolute, we don't want to double-absolutify it :)


function var_is_set {
local -r var_name="$1"
[[ "${!var_name+x}" != '' ]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the +x here?

(Also, this is perfectly fine and readable, but -z (empty string) and -n (non-empty) are handy tests to know about :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants