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

tvOS build.sh help, please #106

Open
shanzez opened this issue Mar 24, 2021 · 6 comments
Open

tvOS build.sh help, please #106

shanzez opened this issue Mar 24, 2021 · 6 comments

Comments

@shanzez
Copy link

shanzez commented Mar 24, 2021

I'm trying to copy the ios build.sh example usage to use for tvos and I've gotten pretty far, but need some help here:

clang -DPACKAGE_NAME=\"cctools\" -DPACKAGE_TARNAME=\"cctools\" -DPACKAGE_VERSION=\"973.0.1\" -DPACKAGE_STRING=\"cctools\ 973.0.1\" -DPACKAGE_BUGREPORT=\"t.poechtrager@gmail.com\" -DPACKAGE_URL=\"\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DEMULATED_HOST_CPU_TYPE=16777228 -DEMULATED_HOST_CPU_SUBTYPE=0 -D__STDC_LIMIT_MACROS=1 -D__STDC_CONSTANT_MACROS=1 -DHAVE_EXECINFO_H=1 -DHAVE_UTIMENSAT=1 -DHAVE_BCOPY=1 -DHAVE_BCMP=1 -DHAVE_BZERO=1 -DHAVE_INDEX=1 -DHAVE_RINDEX=1 -DHAVE_STAT_ST_MTIM=1 -DHAVE_CLOCK_GETTIME=1 -I. -I../../../../../../../cctools/ld64/src/ld   -isystem /opt/cctools-port/usage_examples/tvos_toolchain/target/include -D__DARWIN_UNIX03 -Wall -Wno-long-long -Wno-import -Wno-format -Wno-deprecated -Wno-unused-variable -Wno-unused-private-field -Wno-unused-function -Wno-invalid-offsetof -Wno-int-conversion -Wno-char-subscripts -Wno-shift-negative-value -Wno-misleading-indentation -Wno-gnu-folding-constant -DLTO_SUPPORT -DTAPI_SUPPORT -D__LITTLE_ENDIAN__=1 -I../../../../../../../cctools/include -I../../../../../../../cctools/include/foreign -I../../../../../../../cctools/ld64/src -I../../../../../../../cctools/ld64/src/abstraction -I../../../../../../../cctools/ld64/src/3rd -I../../../../../../../cctools/ld64/src/3rd/BlocksRuntime -I../../../../../../../cctools/ld64/src/ld -I../../../../../../../cctools/ld64/src/ld/parsers -I../../../../../../../cctools/ld64/src/ld/passes -DPROGRAM_PREFIX="\"aarch64-apple-darwin20-\""  -O3 -isystem /usr/local/include -isystem /usr/pkg/include  -DLD64_VERSION_NUM=609 -fblocks -c -o ld-libcodedirectory.o `test -f 'libcodedirectory.c' || echo '../../../../../../../cctools/ld64/src/ld/'`libcodedirectory.c
....
../../../../../../../cctools/ld64/src/ld/libcodedirectory.c:797:23: error: variable-sized object may not be initialized
    uint8_t page_hash[_max_known_hash_len] = {0};
                      ^~~~~~~~~~~~~~~~~~~
../../../../../../../cctools/ld64/src/ld/libcodedirectory.c:804:18: error: variable-sized object may not be initialized
    uint8_t page[_cs_page_bytes] = {0};
                 ^~~~~~~~~~~~~~
2 errors generated.
make[4]: *** [Makefile:578: ld-libcodedirectory.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[4]: Leaving directory '/opt/cctools-port/usage_examples/tvos_toolchain/tmp/cctools/ld64/src/ld'

Basically, I stripped out the same parts of the Xcode.xip for AppleTVOS that I stripped out for iPhoneOS and then made adjustments to the ios_toolchain/build.sh for tvos. It looks like I got pretty far, but maybe I deluding myself.

@shanzez
Copy link
Author

shanzez commented Mar 24, 2021

Also, it appears that the wrapper.c needs adjustment:

    env(&sdk, "IOS_SDK_SYSROOT", sdkpath);
    env(&cpu, "IOS_TARGET_CPU", TARGET_CPU);

    env(&osmin, "IPHONEOS_DEPLOYMENT_TARGET", OS_VER_MIN);
    unsetenv("IPHONEOS_DEPLOYMENT_TARGET");

    snprintf(osvermin, sizeof(osvermin), "-miphoneos-version-min=%s", osmin);

Would it work if I just change those values to APPLETVOS|appletvos?

Finally, I just noticed this at the bottom of my build.sh execution:

*** checking toolchain ***
clang-12: warning: using sysroot for 'AppleTVOS' but targeting 'iPhone' [-Wincompatible-sysroot]
/usr/bin/ld: unrecognized option '-dynamic'
/usr/bin/ld: use the --help option for usage information
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)

I assumed this is coming from this line in build.sh:

echo "int main(){return 0;}" | $TRIPLE-clang -xc -O2 -o test - 1>/dev/null || exit 1

@shanzez shanzez changed the title tvOS build.sh help please tvOS build.sh help, please Mar 24, 2021
tpoechtrager added a commit that referenced this issue Mar 24, 2021
@tpoechtrager
Copy link
Owner

I can't reproduce the variable-sized error. I have tested clang 3.5, 3.6, 3.7, 3.8, 3.9, 4.0.1, 5.0.2, 6.0.1, 7.0.1, 8.0.0, 9.0.0, 10.0.0, 11.0.0, and git ...

What's your OS and your compiler version?

It's -mtvos-version-min=x.x, I think.

@shanzez
Copy link
Author

shanzez commented Mar 25, 2021

I'm very sorry for not getting back to you sooner.

I'm using Apple's llvm https://github.com/apple/llvm-project.git rev
8b8cdf9a9dc095e53269eaf5acfd803ee28c9083

I build it, then build a new version of it with the just built version (so llvm with llvm)

    mkdir llddir && cd lldir &&\
    git init &&\
    git remote add origin https://github.com/apple/llvm-project.git &&\
    git fetch origin 8b8cdf9a9dc095e53269eaf5acfd803ee28c9083 &&\
    git reset --hard FETCH_HEAD && \
    mkdir -p llvm/build clang/build1 clang/build2 &&\
    cd llvm/build &&\
    cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Release \
      -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=1 &&\
    make -j$(nproc --all) install &&\
    cd ${LLDIR}/clang/build1 &&\
    cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Release \
      -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=1 &&\
    make -j$(nproc --all) clang &&\
    cd ../build2 &&\
    CC=${LLDIR}/clang/build1/bin/clang CXX=${LLDIR}/clang/build1/bin/clang++ \
      cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Release \
      -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=1 &&\
    make -j$(nproc --all) install &&\

The OS is Debian buster-20201209-slim and I start out with g++ and llvm-dev installed via apt. I use the above llvm build with my ios (cctools-port) and mac (osxcross) builds too and it has worked fine.

Thank you, sir.

@shanzez
Copy link
Author

shanzez commented Mar 26, 2021

Pulling in your patch 14ab643 and changing -miphoneos-version-min to -mtvos-version-min has me building successfully.

@shanzez
Copy link
Author

shanzez commented Mar 30, 2021

I'm fine if you'd like to close this ticket @tpoechtrager. Thank you again.

@tpoechtrager
Copy link
Owner

Let's keep it open for reference. You might not be the only one who wants a tvOS toolchain. :)

For other OSs:

-mappletvos-version-min=
-mappletvsimulator-version-min=
-mios-simulator-version-min=
-mios-version-min=
-miphoneos-version-min=
-miphonesimulator-version-min=
-mmacos-version-min=
-mmacosx-version-min=
-mtvos-simulator-version-min=
-mtvos-version-min=
-mwatchos-simulator-version-min=
-mwatchos-version-min=
-mwatchsimulator-version-min=

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

No branches or pull requests

2 participants