-
Notifications
You must be signed in to change notification settings - Fork 372
Enable static builds of binaries #495
Comments
Just running a local build now to sanity check the above build with static linking. |
Everything works except
|
Link order issue? A la http://stackoverflow.com/questions/28165518/use-libcurl-undefined-reference-to-curl-easy-init? |
That's puzzling. Not sure why it isn't an issue when building |
Well, if it just a command-line order issue, it would all just be down to the order in which targets were executed. So maybe just some fluky alphabetical thing, where -lcurl is ending up early in this case? |
This is the actual link command (formatted):
I notice that ethminer isn't linking the json rpc server, only the client, so maybe there is some problem from there. |
Manually appending |
'I notice that ethminer isn't linking the json rpc server, only the client, so maybe there is some problem from there." ^ Yeah. I think that this whole stack of "JSON-RPC stuff" which then drags in the curl chain is all a very thin thread of dependencies, but which is a bit messy. I did some minimization before which removed the unnecessary JsonRpc::Server dependency from ethminer. There is probably plenty more which can be trimmed, if we better understood it. Good luck! |
So it looks like part of my CURL REQUIRED thing was due to only having a partially synced workspace, but I've made one clean up which is building now, and then that's good and everything is healthy for the dynamic builds and you just have that curl link order thing for ethminer left. I'm going to try doing static builds for OS X and Windows now, for eth at least, and hopefully more if I have time. |
I've got a Dockerfile for building (unsuccessfully) on Debian here: https://github.com/rainbeam/eth-static/blob/debian/Dockerfile Really minimal curl can be configured with:
However, even if we get past the curl linking problems, there is a bigger problem in that glibc is not designed to be statically linked. The The binary this produces is completely portable across Linux based distros though - the limitation is only in the build environment. As such, I don't regard the Debian / Ubuntu problems as part of this issue. The As for other platforms (other than x86_64)... I've not looked into it much but I saw that there are musl cross compilers provided here: Might be useful in your mobile adventures 😄 . |
Thanks for that extra info, which will indeed be useful. Flipping to a statically linked musl cross-compiled runtime could be very useful. I found that OS X as does not want to be completely statically linked (see https://developer.apple.com/library/mac/qa/qa1118/_index.html), so added checks for that to give an error message rather than just failing. I will try to "weaken that off", so that it statically links everything except the C++ runtime library. Windows can be used with either DLLs or static libraries for the runtime. That will because unlike Linux, there is a binary compatibility guarantee for Windows, which is why old Windows apps work for years and years. Linux, I understand, has never had that, hence the monolithic kernel including drivers for everything under the sun. They have to be in-tree because the ABI can change arbitrarily between kernel and drivers. Seems the ABI guarantee is a bit weak on OS X too. As for curl, yeah, would be great to do a minimal compile like that, and I will certainly refer back to your notes here as-and-when I get around to pulling that in as a sub-module. Did you try building curl like that for your Alpine Linux build? So with such settings, if looks like OpenSSL, ssh2 and zlib would NOT be needed? |
"Manually appending -lcurl -lssh2 -lssl -lcrypto -lssl -lcrypto -lz fixes it (that's the output of pkg-config --libs --static libcurl). Now just need to coerce cmake into adding it." ^ Did you manage to work out the magic spell for this, btw? :-) |
No. I messed around a bit with moving the Also tried a bit more with Debian. I reckon it is possible to build fully static by using https://github.com/rainbeam/eth-static/tree/ethminer https://github.com/rainbeam/eth-static/tree/debian
|
Just did an Alpine build with minimal curl - ssh2, openssl and zlib appear not to be needed. |
Thanks for the update. I've been doing a partially static build for OS X, with some success, and will try Windows as well when I get a chance. "Just did an Alpine build with minimal curl - ssh2, openssl and zlib appear not to be needed." - That is good to know, and makes sense. OS X static build is pulling in Snappy as an indirect dependency of leveldb, which is a bit weird, but I suspect it is just an artifact of the fact that leveldb is still a dylib dependency at the partial stage I got to:
So, getting to a static binary isn't possible on OS X, but statically linking all the libs should be possible. The binary I have right now runs just fine, but the following libs are still using .dylib, not .a:
To get those ones statically linking, I'll need to build them from source. libz and curl ship as part of the platform, but again I could build them from source and statically link them. |
PS. OS X partially statically linked executable is 12MB. |
OK - So testing this for Windows is a horror-show, because we'll need LIB files for all the pre-built external dependencies. I'm going to defer that for now. So @rainbeam ... are you pretty much done here now? And you still didn't work out a magic-mantra to get the libcurl ordering thing resolved, right? That was on Debian? Or Alpine? |
Yeah I think I'm done here. Couldn't resolve the libcurl problem, except by manually modifying the link command after cmake was configured. This only affects Debian has the added problem of glibc, which isn't going to statically link. A similar solution to OSX (i.e. dynamic linking the system libs) might be needed if people want to build on that platform (rather than just use a static binary compiled on a musl system). Alternatively, Debian does have Thanks for your help on this Bob :) |
FYI ... My first Boost post made it through their filters ... http://lists.boost.org/Archives/boost/2016/05/229385.php ... the one about thread setname/getname. And got a first reply: |
See boostorg/thread#84, where there is now an issue tracking the Boost TODO, which I have offered to put on my backlog. |
BTW - @Genoil - fyi - all this stuff :-) ^^^^ |
@bobsummerwill I've been talking to JW all along. |
I get a page not found error for the unity link. On Aug 8, 2016 19:59, "Bob Summerwill" notifications@github.com wrote:
|
Some more unity-build links, @nerdralph:
RE: Talking to Genoil. Great! |
@bobsummerwill The info you provided on unity/blob builds shows it to be a hack, and it would even seem to break some things (like static in C). |
Just did some testing and found out that lto breaks the build with g++-5.3 and 6.1 :-( |
Oh yeah, @nerdralph. It absolutely is a hack, but a hack with beautiful upside in terms of developer productivity. It is very easy to counter the downsides, by maintaining both "loose" and 'BulkBuild" modes within your automated build process, but just using "BulkBuild" by default for your local builds. You do sometimes need to make minor changes to avoid symbol clashes when force-combining compilation units in that way, but they are surprisingly easy to resolve. The upside is that your builds are like 10x faster, which is a productivity benefit which it is very hard to argue with. RE: Nested includes ... I don't see that in your referenced Chromium guide. I have seen old advice saying that you should never include headers within headers, which is god-awful advice. The bible for a lot of this physical dependencies stuff is 10 years old now, but most C++ developers have never even heard of it :-) https://www.amazon.ca/Large-Scale-Software-Design-John-Lakos/dp/0201633620 |
What do those LTO breaks look like, @nerdralph? |
With -flto I was getting lots of undefined refernce errors with gcc-5.3 and gcc-6.1, but not with 4.8. As a quick hack, I tried renaming ar to ar-binutils and making a symlink to gcc-ar, only to find that it crashed my machine when building! |
@bobsummerwill Re build speedups, I assume you are talking about on Windoze/VC++. Real developers use Unix ;-) |
Solved the lto issue with by setting CMAKE_AR and CMAKE_RANLIB to gcc-ar and gcc-ranlib. |
Build speedups are for all compilers, because all C++ toolsets are subject to the redundant work per compilation unit for the pre-processor. Well, maybe pre-compiled headers can help a bit, but they really don't. "Bible" in terms of physical dependencies in C++, which is something that most people don't even think about. Do get yourself a copy if you haven't seen it. I think that you will really enjoy it, though some of it looks a little dated. 1% smaller? Yeah - not so hot! |
I was just dicking about with BulkBuild on my MacBook Air. |
@bobsummerwill If there was a way for you to lend me a copy of it, I'd read it, but I can't think of any books I consider worth $54! My favorite book, "Blink" by Malcolm Gladwell costs less than $20 in paperback. |
I just timed the build with gcc-6.1 (lto enabled), G1840 dual-core celeron, 2G RAM, 400G 2.5" SATA HD. |
Second hand copies on Amazon from $2.50 + ~$4 for shipping. Nice. Linux certainly pisses on Mac for build times. Your build times will be crazy fast with BulkBuild added too. I'm seeing about 30mins -> 10 mins for the whole of cpp-ethereum, with some more work to do to unhack it into a state where I could commit. |
Fat finger! |
@bobsummerwill That was just a single-threaded make. make -j2 is even faster: Normal development builds where you change a file or two and rebuild is in the range of 30s. |
@bobsummerwill I found some of his book online (he published several articles in the C++ Report that went into the book). Seems pretty mundane, and nothing I didn't already know so far. p.s. And the more I read the less I like it. His Stack class uses an int for the index (d_sp) and size, while a smart developer would use unsigned int. |
Well - no doubt plenty of his examples look dated for syntax, yes. His writing is primarily on physical dependencies and architecture - and really on the consequences of header files, compilation units, etc. |
C++ has always had unsigned, and the pitfalls of using int for things that On Aug 9, 2016 00:45, "Bob Summerwill" notifications@github.com wrote: Well - no doubt plenty of his examples look dated for syntax, yes. His writing is primarily on physical dependencies and architecture - and — |
Great - so my EOD time for cpp-ethereum building (all apps) is now 7 mins on my machine, where that process currently takes around 30-46 mins in Travis, depending on the OS X version. I like those numbers. Will clean it up tomorrow, to make a PR which could be submitted soon after the repo-move back to ethereum/cpp-ethereum. I'll do a PR-on-a-PR-on-a-PR: merge_repos -> cmake_fixes -> bulkbuild_support. Good night! |
Following on from ethereum/webthree-helpers#157, enable static linking of some more binaries by switching
add_executable
toeth_simple_add_executable
.This is a master issue. Target binaries:
eth
add_exe
link eth binary with custom add_executable webthree#163solc
Use add exe wrapper for solc, soltest, lllc solidity#528soltest
^lllc
^ethminer
add_exe
Use add_exe wrapper for ethminer libethereum#248-lcurl
ordering issueSTATIC_LINKING
across platformsThe text was updated successfully, but these errors were encountered: