-
Notifications
You must be signed in to change notification settings - Fork 190
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 target-prefixed executables to the installation bin
directory
#388
Add target-prefixed executables to the installation bin
directory
#388
Conversation
I should say that another motivation for this is that we'll want the preview2 target to output a component by default, not a core module, and for that purpose rustc will use |
I've been imagining we'd add the It isn't really idiomatic for clang to have target-prefixed executables, because clang has the ability to support multiple targets in the same build. What would you think of instead installing Also, regardless of what we call the new commands, what would you think of putting them in a |
Ah ok, I think I'm too used to distros and gcc things then. If it's not idiomatic for clang to have target-prefixes I agree this needs to change. I suppose then this raises a bit of a larger question of if there's a longer-term installation plan for wasi-sdk perhaps? For example is the goal on macOS, for example, to enable Do you know how feasible it would be to modify Clang to support Also, yeah, I'm happy to make a |
I think as long as you add wasi-sdk to the end of the |
I'm not totally sure that is totally true. I believe there is precedent out there for target-prefixed clang binaries. For example android NDK ship no less that 57 target prefixed versions of clang++:
I believe the mechansim for setting the default target based on the executable name is built into clang itself, so these can all by symlinks or copies of the primary I've personally found it useful in the past to be able do Another advantage of |
I wonder if we could use clang's own builtin mechanism for creating links / copies of the clang binary: https://github.com/llvm/llvm-project/blob/1e828f838cc0f15074f3dbbb04929c06ef0c9729/clang/cmake/modules/AddClang.cmake#L185-L197 I thought there would be some existing CMake code in clang for creating arch-prefixed links, but I didn't find it in my initial search. I looks like we could set That clang driver also has a builtin mechanism for setting the default target based on the executable name, so I don't think there is any need to invent our own one here. |
Clang code for setting up target based on executable name: https://github.com/llvm/llvm-project/blob/f836048a2b452f5f2a8440c9f5945ee1a7bcdac2/clang/include/clang/Driver/ToolChain.h#L331-L345 |
as clang recognizes prefixes as @sbc100 said, i suppose it makes sense for us to ship prefixed symlinks in a separate bin dir.
|
Prefixed binaries will help simplify MLton/mlton#550. I appreciate this proposed improvement. |
Thanks @sbc100! I was unaware clang had that, and that other cross-sdks used it that way. That sounds like a good approach to me. |
@alexcrichton I understand the motivation behind having a component as a default one for the preview2, but will there be an option to use wasm-ld directly for rustc/clang? I think there are usecases where people just want to build a core module with preview2 canonical ABI only, so having a flag to disable component model would be really helpful. |
Currently the `bin` directory installed by wasi-sdk is not currently suitable for putting in `$PATH` in all cases because it can shadow a system-installed `clang` executable which is intended for native binaries. For Linux distributions with gcc-based cross-compilers I've often seen the pattern where they're installed as `$target-gcc` and so I've taken a leaf out of their books to do that here as well. This commit adds, currently alongside the preexisting `clang` executable, target-prefixed executables such as `wasm32-wasi-clang` and `wasm32-wasi-clang++`. These executables are symlinks to the `clang` executable itself in the same manner that `clang++` is a symlink to `clang` itself. I'll also note that this doesn't fix the problem of "add the wasi-sdk bin dir to PATH" because `clang` and other prominent executables are still there. My hope though is that this opens up a future refactoring for doing so.
5cc4883
to
c2e39c9
Compare
If executing target-prefixed executables, yes, but IMO that's pretty brittle. In the long term I still think it'd be good to have a directory that can be unambiguously added to
Thanks for pointing that out! (as well as the precedent and code Clang already has to handle this!) I've now updated this PR to using this strategy instead to install symlinks for each target.
Yes both clang and rustc allow configuring the linker, there's no need to use the built-in default. And also, yes, my plan is to add a flag of some sort to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Nice to see that CLANG_LINKS_TO_CREATE works.
# list with a defined separator. | ||
noop = | ||
space = $(noop) $(noop) | ||
join-with = $(subst $(space),$1,$(strip $2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shame that we have to resort for this kind of Makefile magic, but I am not well versed enough to suggest anything better :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed :(
I went through a number of iterations of "copy some bits and pieces from stack overflow" until I found this which ended up working well enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the PR description now that a new technique is being used?
Ah yes indeed, and thanks for the review! |
I noticed that WebAssembly#388 increased the size of the Windows distribution by 200M+ and my guess for that is that all the symlinks which point to clang get copied as real files (due to symlinks not always working on Windows). To help counteract that this commit enables the `LLVM_LINK_LLVM_DYLIB=ON` option when building LLVM and Clang. That should build a `libLLVM.so` which helps reduce the size of all the tools since they no longer all statically link LLVM. Locally the size of a full build is ~100M less as a result of this change. On Windows where all the binaries are copied around it should hopefully help much more. I've additionally taken a leaf out of rust-lang/rust's book of building LLVM to pass the `LLVM_VERSION_SUFFIX` option here too. That I believe helps avoid `libLLVM.so` conflicting with a system-installed `libLLVM.so` by accident by ensuring there's a suffix present on the binaries built for wasi-sdk.
I noticed that WebAssembly#388 increased the size of the Windows distribution by 200M+ and my guess for that is that all the symlinks which point to clang get copied as real files (due to symlinks not always working on Windows). To help counteract that this commit enables the `LLVM_LINK_LLVM_DYLIB=ON` option when building LLVM and Clang. That should build a `libLLVM.so` which helps reduce the size of all the tools since they no longer all statically link LLVM. Locally the size of a full build is ~100M less as a result of this change. On Windows where all the binaries are copied around it should hopefully help much more. I've additionally taken a leaf out of rust-lang/rust's book of building LLVM to pass the `LLVM_VERSION_SUFFIX` option here too. That I believe helps avoid `libLLVM.so` conflicting with a system-installed `libLLVM.so` by accident by ensuring there's a suffix present on the binaries built for wasi-sdk.
For posterity here: For the wasm32-wasip2 targets and using |
This is to reflect the upstream change in WebAssembly/wasi-sdk#388.
This is to reflect the upstream change in WebAssembly/wasi-sdk#388.
Currently the
bin
directory installed by wasi-sdk is not currentlysuitable for putting in
$PATH
in all cases because it can shadow asystem-installed
clang
executable which is intended for nativebinaries. For Linux distributions with gcc-based cross-compilers I've
often seen the pattern where they're installed as
$target-gcc
and soI've taken a leaf out of their books to do that here as well.
This commit adds, currently alongside the preexisting
clang
executable, target-prefixed executables such as
wasm32-wasi-clang
andwasm32-wasi-clang++
. These executables are symlinks to theclang
executable itself in the same manner that
clang++
is a symlink toclang
itself.I'll also note that this doesn't fix the problem of "add the wasi-sdk
bin dir to PATH" because
clang
and other prominent executables arestill there. My hope though is that this opens up a future refactoring
for doing so.