diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8489c3cc..88ccda09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,6 @@ jobs: - catb.org/wumpus - c-ares.org - vim.org - - tea.xyz/gx/cc # FIXME? requires a darwin platform to run, and needs # macOS 12 to test. That'll require a more complex matrix # using get-platform. @@ -29,23 +28,24 @@ jobs: - uses: actions/checkout@v3 - uses: teaxyz/setup@v0 - - name: configure PATH - run: echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH + - run: | + find ~/.tea/tea.xyz/var/pantry -name 'package.yml' -exec sed -i '/tea\.xyz\/gx\/cc: c99/d' {} \; - - uses: actions/cache@v3 - with: - path: ${{ env.HOME }}/.cache/deno - key: deno-get-platform-${{ hashFiles('deno.jsonc')}} + # prefetch dneo deps to make the output from the build step more legible + - run: deno cache **/*.ts - - name: prefetch deno deps - # this makes the output from the build step more legible - run: deno cache **/*.ts + - name: install brewkit + run: | + mkdir -p "$HOME/.tea/tea.xyz/brewkit/v*" + mv * "$HOME/.tea/tea.xyz/brewkit/v*" + echo "$HOME/.tea/tea.xyz/brewkit/v*/bin" >> $GITHUB_PATH - run: pkg build ${{matrix.pkgs}} id: build - run: test -n '${{ steps.build.outputs.pkgs }}' - run: test -n '${{ steps.build.outputs.relative-paths }}' + - run: | if pkg query ${{ steps.build.outputs.pkgs }} --src 2>&1 | grep -E '^warn: pkg has no srcs:'; then echo "srcs=false" >> $GITHUB_OUTPUT @@ -53,8 +53,10 @@ jobs: echo "srcs=true" >> $GITHUB_OUTPUT fi id: srcs + - run: test -n '${{ steps.build.outputs.srcs }}' if: steps.srcs.outputs.srcs == 'true' + - run: test -n '${{ steps.build.outputs.srcs-relative-paths }}' if: steps.srcs.outputs.srcs == 'true' diff --git a/lib/usePantry.getScript.ts b/lib/usePantry.getScript.ts index efbd4a76..d27cc406 100644 --- a/lib/usePantry.getScript.ts +++ b/lib/usePantry.getScript.ts @@ -1,3 +1,4 @@ +import useConfig from "libtea/hooks/useConfig.ts" import { SupportedPlatforms } from "https://raw.githubusercontent.com/teaxyz/lib/v0.4.2/src/utils/host.ts" import { isArray, isString, isPlainObject, PlainObject } from "is-what" import { Package, Installation, hooks, utils, semver } from "libtea" @@ -13,6 +14,9 @@ export const getScript = async (pkg: Package, key: 'build' | 'test', deps: Insta const mm = useMoustaches() const script = (input: unknown) => { const tokens = mm.tokenize.all(pkg, deps) + tokens.push({ + from: "build.root", to: useConfig().prefix.string + }) if (isArray(input)) input = input.map(obj => { if (isPlainObject(obj)) { diff --git a/libexec/stage-test.ts b/libexec/stage-test.ts index 985ef6e2..add334be 100755 --- a/libexec/stage-test.ts +++ b/libexec/stage-test.ts @@ -43,6 +43,11 @@ if (!yml.test) throw "no `test` node in package.yml" env['PATH'] ??= [] env['PATH'].push("/usr/bin:/bin") +if (!deps.find(({pkg}) => pkg.project == 'llvm.org' || pkg.project == 'gnu.org/gcc')) { + /// add our helper cc toolchain unless the package has picked its own toolchain + env['PATH'].push(new Path(new URL(import.meta.url).pathname).parent().parent().join("share/toolchain/bin").string) +} + let text = undent` #!/usr/bin/env bash diff --git a/libexec/stage.ts b/libexec/stage.ts index 07aca917..6a943b57 100755 --- a/libexec/stage.ts +++ b/libexec/stage.ts @@ -56,7 +56,12 @@ const pkg = await pantry.resolve(parse(pkgname)) /// assemble build script const pantry_sh = await pantry.getScript(pkg, 'build', deps) -const brewkit = new Path(new URL(import.meta.url).pathname).parent().parent().join("share/brewkit") +const sup_PATH = [new Path(new URL(import.meta.url).pathname).parent().parent().join("share/brewkit")] + +if (!deps.find(({pkg}) => pkg.project == 'llvm.org' || pkg.project == 'gnu.org/gcc')) { + /// add our helper cc toolchain unless the package has picked its own toolchain + sup_PATH.push(new Path(new URL(import.meta.url).pathname).parent().parent().join("share/toolchain/bin")) +} /// calc env const sh = useShellEnv() @@ -86,7 +91,7 @@ const text = undent` mkdir -p "$HOME" - export PATH=${brewkit}:"$PATH" + export PATH=${sup_PATH.map(x => x.string).join(':')}:"$PATH" export CFLAGS="-w $CFLAGS" # warnings are noise ${pantry_sh} diff --git a/share/.DS_Store b/share/.DS_Store new file mode 100644 index 00000000..2d42a62b Binary files /dev/null and b/share/.DS_Store differ diff --git a/share/TEMPLATE.pkg.yml b/share/TEMPLATE.pkg.yml index 74acf192..d4d1a88d 100644 --- a/share/TEMPLATE.pkg.yml +++ b/share/TEMPLATE.pkg.yml @@ -80,14 +80,13 @@ dependencies: build: dependencies: - tea.xyz/gx/cc: c99 - tea.xyz/gx/make: '*' - # ^^ often packages need dependencies to build, it is very common for - # packages to need a C compiler and make, the above provide those + cmake.org: ^3 + # ^^ we provide a c compiler and make by default, other deps you’ll need to add yourself + script: | ./configure $ARGS make --jobs {{ hw.concurrency }} install - # it’s extremely common for packages to require the above + # ^^ it’s extremely common for packages to require the above # script also supports a list of commands, which is useful for complex builds # or if you want to run a command in a different directory diff --git a/share/toolchain/.DS_Store b/share/toolchain/.DS_Store new file mode 100644 index 00000000..24516ca8 Binary files /dev/null and b/share/toolchain/.DS_Store differ diff --git a/share/toolchain/bin/ar b/share/toolchain/bin/ar new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/ar @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/as b/share/toolchain/bin/as new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/as @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/c++ b/share/toolchain/bin/c++ new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/c++ @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/cc b/share/toolchain/bin/cc new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/cc @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/clang b/share/toolchain/bin/clang new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/clang @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/clang++ b/share/toolchain/bin/clang++ new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/clang++ @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/cpp b/share/toolchain/bin/cpp new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/cpp @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/g++ b/share/toolchain/bin/g++ new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/g++ @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/gcc b/share/toolchain/bin/gcc new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/gcc @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/ld b/share/toolchain/bin/ld new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/ld @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/ld64.lld b/share/toolchain/bin/ld64.lld new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/ld64.lld @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/lld b/share/toolchain/bin/lld new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/lld @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/lld-link b/share/toolchain/bin/lld-link new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/lld-link @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/make b/share/toolchain/bin/make new file mode 100755 index 00000000..b6682e4f --- /dev/null +++ b/share/toolchain/bin/make @@ -0,0 +1,7 @@ +#!/bin/sh + +if [ $(uname) = Darwin ]; then + exec /usr/bin/make "$@" +else + exec tea +gnu.org/make make "$@" +fi diff --git a/share/toolchain/bin/nm b/share/toolchain/bin/nm new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/nm @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/objcopy b/share/toolchain/bin/objcopy new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/objcopy @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/ranlib b/share/toolchain/bin/ranlib new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/ranlib @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/readelf b/share/toolchain/bin/readelf new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/readelf @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/strings b/share/toolchain/bin/strings new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/strings @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/bin/strip b/share/toolchain/bin/strip new file mode 120000 index 00000000..075dad11 --- /dev/null +++ b/share/toolchain/bin/strip @@ -0,0 +1 @@ +../shim \ No newline at end of file diff --git a/share/toolchain/shim b/share/toolchain/shim new file mode 100755 index 00000000..13466e3f --- /dev/null +++ b/share/toolchain/shim @@ -0,0 +1,85 @@ +#!/bin/sh + +tool=$(basename $0) + +if [ $(uname) != Darwin ]; then + d="$(cd "$(dirname "$0")/.." && pwd)" + exec "$TEA_PREFIX/tea.xyz/v*/bin/tea" +llvm.org $d/symlinks/$tool "$@" +fi + +case $tool in +cc|gcc|clang|c++|g++|clang++) + exec ruby $0 "$@" + ;; +ld|lld|lld-link|ld64.lld) + for word in "$@"; do + if test "$word" = -r; then + exec /usr/bin/"$tool" "$@" + fi + done + + exec /usr/bin/$tool "$@" -rpath "${TEA_PREFIX:-$HOME/.tea}" + ;; +*) + exec /usr/bin/$tool "$@" + ;; +esac + + +#!/usr/bin/ruby + +# - we inject our rpath to ensure our libs our found +# - for bottles we replace that in fix-machos.rb with a relocatable prefix +# - in general usage we don’t, so if the user needs to distribute their artifacts, +# they will need to fix them first, but that's typical anyway. + +$tea_prefix = ENV['TEA_PREFIX'] || (ENV['HOME'] + "/.tea") +exe = File.basename($0) + +# remove duplicates since this in fact embeds the rpath multiple times +# and omit -nodefaultrpaths since it is not a valid flag for clang +args = ARGV.map do |arg| + arg unless arg == "-Wl,-rpath,#$tea_prefix" or arg == "-nodefaultrpaths" +end.compact + +def is_tea? path + path = File.realpath path while File.symlink? path + return File.basename(path) == "tea" +end + +# find next example of ourselves +# this will either pick the Apple provided clang or the tea one +exe_path = ENV['PATH'].split(":").filter { |path| + if path == File.dirname(__FILE__) + false + elsif path == File.join($tea_prefix, ".local/bin") + false + elsif is_tea?(path) + false + else + true + end +}.map { |path| + "#{path}/#{exe}" +}.reject { |path| + # if the user created a symlink of `cc` to `tea` don’t use it + File.symlink? path and File.basename(File.readlink(path)) == "tea" +}.find { |path| + File.exist?(path) +} + +abort "couldn’t find #{exe} in `PATH`" unless exe_path + +for arg in args do + # figuring out what “mode” we are operating in is hard + # we don’t want to add this linker command always because it causes a warning to be + # output if we are not outputing executables/dylibs and this warning can break + # configure scripts, however the below is not fully encompassing + # we aren't sure what the rules are TBH, possibly it is as simple as if the output (`-o`) + # is a .o then we don’t add the rpath + if arg.start_with? '-l' or arg.end_with? '.dylib' + exec exe_path, *args, "-Wl,-rpath,#$tea_prefix" + end +end + +exec exe_path, *args diff --git a/share/toolchain/symlinks/ar b/share/toolchain/symlinks/ar new file mode 120000 index 00000000..d03f9ca4 --- /dev/null +++ b/share/toolchain/symlinks/ar @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/llvm-ar \ No newline at end of file diff --git a/share/toolchain/symlinks/as b/share/toolchain/symlinks/as new file mode 120000 index 00000000..6282f5f0 --- /dev/null +++ b/share/toolchain/symlinks/as @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/llvm-as \ No newline at end of file diff --git a/share/toolchain/symlinks/c++ b/share/toolchain/symlinks/c++ new file mode 120000 index 00000000..be134fe6 --- /dev/null +++ b/share/toolchain/symlinks/c++ @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/clang++ \ No newline at end of file diff --git a/share/toolchain/symlinks/cc b/share/toolchain/symlinks/cc new file mode 120000 index 00000000..fec4d088 --- /dev/null +++ b/share/toolchain/symlinks/cc @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/clang \ No newline at end of file diff --git a/share/toolchain/symlinks/clang b/share/toolchain/symlinks/clang new file mode 120000 index 00000000..fec4d088 --- /dev/null +++ b/share/toolchain/symlinks/clang @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/clang \ No newline at end of file diff --git a/share/toolchain/symlinks/clang++ b/share/toolchain/symlinks/clang++ new file mode 120000 index 00000000..be134fe6 --- /dev/null +++ b/share/toolchain/symlinks/clang++ @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/clang++ \ No newline at end of file diff --git a/share/toolchain/symlinks/cpp b/share/toolchain/symlinks/cpp new file mode 120000 index 00000000..fd140024 --- /dev/null +++ b/share/toolchain/symlinks/cpp @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/clang-cpp \ No newline at end of file diff --git a/share/toolchain/symlinks/g++ b/share/toolchain/symlinks/g++ new file mode 120000 index 00000000..be134fe6 --- /dev/null +++ b/share/toolchain/symlinks/g++ @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/clang++ \ No newline at end of file diff --git a/share/toolchain/symlinks/gcc b/share/toolchain/symlinks/gcc new file mode 120000 index 00000000..fec4d088 --- /dev/null +++ b/share/toolchain/symlinks/gcc @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/clang \ No newline at end of file diff --git a/share/toolchain/symlinks/ld b/share/toolchain/symlinks/ld new file mode 120000 index 00000000..72b7a64d --- /dev/null +++ b/share/toolchain/symlinks/ld @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/lld \ No newline at end of file diff --git a/share/toolchain/symlinks/ld64.lld b/share/toolchain/symlinks/ld64.lld new file mode 120000 index 00000000..11c4841b --- /dev/null +++ b/share/toolchain/symlinks/ld64.lld @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/ld64.lld \ No newline at end of file diff --git a/share/toolchain/symlinks/lld b/share/toolchain/symlinks/lld new file mode 120000 index 00000000..72b7a64d --- /dev/null +++ b/share/toolchain/symlinks/lld @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/lld \ No newline at end of file diff --git a/share/toolchain/symlinks/lld-link b/share/toolchain/symlinks/lld-link new file mode 120000 index 00000000..e6a4cca3 --- /dev/null +++ b/share/toolchain/symlinks/lld-link @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/lld-link \ No newline at end of file diff --git a/share/toolchain/symlinks/nm b/share/toolchain/symlinks/nm new file mode 120000 index 00000000..b0a220ee --- /dev/null +++ b/share/toolchain/symlinks/nm @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/llvm-nm \ No newline at end of file diff --git a/share/toolchain/symlinks/objcopy b/share/toolchain/symlinks/objcopy new file mode 120000 index 00000000..d2de81c0 --- /dev/null +++ b/share/toolchain/symlinks/objcopy @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/llvm-objcopy \ No newline at end of file diff --git a/share/toolchain/symlinks/ranlib b/share/toolchain/symlinks/ranlib new file mode 120000 index 00000000..e097d25a --- /dev/null +++ b/share/toolchain/symlinks/ranlib @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/llvm-ranlib \ No newline at end of file diff --git a/share/toolchain/symlinks/readelf b/share/toolchain/symlinks/readelf new file mode 120000 index 00000000..34a0b971 --- /dev/null +++ b/share/toolchain/symlinks/readelf @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/llvm-readelf \ No newline at end of file diff --git a/share/toolchain/symlinks/strings b/share/toolchain/symlinks/strings new file mode 120000 index 00000000..4a69e6d8 --- /dev/null +++ b/share/toolchain/symlinks/strings @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/llvm-strings \ No newline at end of file diff --git a/share/toolchain/symlinks/strip b/share/toolchain/symlinks/strip new file mode 120000 index 00000000..803b830c --- /dev/null +++ b/share/toolchain/symlinks/strip @@ -0,0 +1 @@ +../../../../../../llvm.org/v*/bin/llvm-strip \ No newline at end of file