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

New build tool + host toolchain integration #113

Closed
wants to merge 21 commits into from

Conversation

beeselmane
Copy link
Contributor

This is a bit of a giant pr, but I'll do my best to explain. See tools/rc/README.md for a description of the new setup.sh and rc scripts.

Effectively, this commit does two major things:

  1. Add a new build tool to automate host tooling + cmake invokation
  2. Add sources to build a host toolchain to be used to build the target system.

I've added the tool rc which is to build the host toolchain and invoke system builds/rebuilds, keeping track of where all the host tools are installed to. This pr includes a full system building toolchain, including the full llvm-project, cctools, linker, and a few misc. tools Apple includes with their toolchain. The toolchain is by default installed to the products/toolchain directory, and the system root is installed to the products/root directory.

The new tools can be used by sourcing tools/rc/setup.sh once per session, configuring any environment variables desired, and simply invoking rc build to build and install the target system sources. Note that if the toolchain doesn't exist, it may be necessary to invoke first rc --make-host-toolchain to build it.

Included with this pr there are now two submodules: the ninja build tool and Apple's clone of llvm-project. Ensure these two submodules are properly checked out before running rc.

This needs more testing. It currently works very well on my M1 Macbook Pro (host tools target native system; target system is built for x86_64 arch), but it hasn't been tested in other setups. We've nearly gotten it to build on an older macOS version in the discord, but we could use some further testing on other people's macs.

Currently, macOS is required, but with this new setup, it shouldn't be too hard to port the build system to other systems, since we would need only to modify the build scripting for the host toolchain, and the target build would remain the same.

More changes to come,
-- Tyler

Also, ensure no install paths have a leading '/' character.
Note: The dbuild submodule currently points to my own fork of PureDarwin/dbuild.
This will need to be fixed if this is merged back to PureDarwin/PureDarwin
Rename cctools-973.0.1 --> cctools
Use in-tree dtrace sources to build the three ctf tools with rc
All cctools binaries now build into the host toolchain.
The main missing component is now the linker
The imported tools (versions) are:
- bison (bison-14)
- bootstrap_cmds (bootstrap_cmds-122)
- developer_cmds (developer_cmds-66)
- gm4 (gm4-16)
- gnumake (gnumake-132)
- gperf (gperf-13)
flex-26
This adds a few binaries, and moves the unifdef tool
Added bison, gm4, gnumake, gperf, and a few utilities from the ld64 sources
Also import CommonCrypto-60191.100.1, as this is needed for a specific header.
TAPI support has been removed from the linker, but other than that it builds just fine.
There are still some issues, I need to go through the kernel build process in more depth, and then it's just getting everything to build together...
Use compiler internals headers from toolchain in libsystem_kernel
The following versions of these libraries are imported:
libSystem-1311.100.3
libm-2026
libnotify-301
libinfo-554
libclosure-79.1
libunwind-201
removefile-60
keymgr-31
copyfile-180.100.3
UserNotification-31

configd-1163.100.19.0.2
syslog-392.100.2
This will allow us to remove the host dependency on Darwin, as well as better segregate toolchain and host source
This reverts commit 877c5b3.

With the new build system, architecture configuration is handled automatically by rc, so this is not necessary.
@beeselmane
Copy link
Contributor Author

A few notes since I noticed how absolutely giant this pr is. This effectively implements the design we talked about previously here.

Most of the imported files and such are all just pulling in Apple's code for development tools. These repos have been placed in src/Developer. I've also pulled in a few more components of libSystem into src/Libraries. The main things to review for this pr are in the following locations:

cmake/toolchain.cmake -- The cross compilation toolchain definitions used by rc.
tools/*/CMakeLists.txt -- The various setups to build various host tools.
tools/rc/{setup.sh,rc} -- The actual build script I've written.
src/Kernel/xnu/CMakeLists.txt -- Some changes to ensure the XNU build uses the new host tools we create.

Other changes are mainly small and meaningless

@wjk
Copy link
Contributor

wjk commented Dec 10, 2022

I have just pulled your changes into the rc branch of this repo. Feel free to make PRs there. I will merge it into the main branch when it is time for us to switch over to the new toolchain. I do not know how much more work is needed. I suspect not a lot.

Since I’m not merging this PR into main, GitHub will show it as closed instead of merged. This PR has been accepted.

@wjk wjk closed this Dec 10, 2022
@wjk wjk mentioned this pull request Dec 11, 2022
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.

None yet

2 participants