tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.13k stars 1.45k forks source link

tdweb for browser #2625

Closed pfeux closed 1 year ago

pfeux commented 1 year ago

I am trying to build tdweb for the browser and following the instructions from ReadMe at https://github.com/tdlib/td/tree/master/example/web.

When I try to run ./build-tdlib.sh step I get the following error:

-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:9 (project):
  No CMAKE_CXX_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.

Upon running individual lines from build-tdlib.sh, I found the error is thrown at https://github.com/tdlib/td/blob/97ec3eacf4820e05d09c9c2eade995522509cbe0/example/web/build-tdlib.sh#L28

Can you please help me with the error?

Thanks

levlam commented 1 year ago

Did you run source ./emsdk_env.sh from emsdk directory to set up the correct build environment?

pfeux commented 1 year ago

Yes I did run

levlam commented 1 year ago

Then recheck that source ./emsdk_env.sh was run with non-emptinness of results of env | grep PATH | grep fastcomp/emscripten and env | grep EMSDK commands.

pfeux commented 1 year ago

Hi @levlam this is the output when i run source ./emsdk_env.sh

image

levlam commented 1 year ago

The output of the command is fine.

Did you install all TDLib dependencies described in https://github.com/tdlib/td#building? You can find the correct command for this in https://tdlib.github.io/td/build.html?language=C%2B%2B.

pfeux commented 1 year ago

Currently I am installing

apt-get install make git zlib1g-dev libssl-dev gperf php-cli cmake clang-14 libc++-dev libc++abi-dev sed tar wget python3 python-is-python3
levlam commented 1 year ago

This should be enough for cmake to find clang as C++ compiler. Ther should be no error "No CMAKE_CXX_COMPILER could be found." in the mentioned line if clang was installed system-wide.

pfeux commented 1 year ago

This is what I am doing

Below is my Dockerfile

FROM ubuntu

WORKDIR /app
COPY build-td.sh /app/build-td.sh
RUN sed -i -e 's/\r$//' /app/build-td.sh
RUN chmod +x build-td.sh
RUN ./build-td.sh

And below is my build-td.sh file

#!/bin/bash
TZ=America/New_York
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
DEBIAN_FRONTEND=noninteractive

apt-get update && apt-get upgrade -y && apt-get autoremove -y
apt-get install make git zlib1g-dev libssl-dev gperf php-cli cmake clang-14 libc++-dev libc++abi-dev sed tar wget python3 python-is-python3 -y

cd /app
git clone https://github.com/tdlib/td.git
git clone https://github.com/emscripten-core/emsdk.git

cd /app/emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh

cd /app/td/example/web
./build-openssl.sh
./build-tdlib.sh
./copy-tdlib.sh
./build-tdweb.sh

And then running the following command to build the docker docker build --progress plain -t tdbuilder .

I request you humbly to please try running these on your system to see if you are facing any errors?

levlam commented 1 year ago

Ah. I see another issue in the commands. To use clang-14 you need to export environment variables CXXFLAGS="-stdlib=libc++", CC=/usr/bin/clang-14 and CXX=/usr/bin/clang++-14. Alternatively, you can install clang package instead of clang-14.

pfeux commented 1 year ago

So that fixed the previous error but now I am facing the following error when ./build-tdlib.sh executes:

#10 2758.6 [ 98%] Linking CXX static library libtdjson_static.a
#10 2758.7 [ 98%] Built target tdjson_static
#10 2758.7 [100%] Building CXX object CMakeFiles/td_asmjs.dir/td/telegram/td_emscripten.cpp.o
#10 2759.4 [100%] Linking CXX executable td_asmjs.js
#10 2759.5 em++: warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]
#10 2924.9 /app/emsdk/upstream/emscripten/third_party/terser/terser.js:5999
#10 2924.9             generator(self, stream);
#10 2924.9             ^
#10 2924.9
#10 2924.9 RangeError: Maximum call stack size exceeded
#10 2924.9     at doit (/app/emsdk/upstream/emscripten/third_party/terser/terser.js:5999:13)
#10 2924.9     at AST_Break.<anonymous> (/app/emsdk/upstream/emscripten/third_party/terser/terser.js:6006:13)
#10 2924.9     at /app/emsdk/upstream/emscripten/third_party/terser/terser.js:6275:22
#10 2924.9     at Array.forEach (<anonymous>)
#10 2924.9     at display_body (/app/emsdk/upstream/emscripten/third_party/terser/terser.js:6266:14)
#10 2924.9     at /app/emsdk/upstream/emscripten/third_party/terser/terser.js:6330:17
#10 2924.9     at /app/emsdk/upstream/emscripten/third_party/terser/terser.js:5754:19
#10 2924.9     at OutputStream.with_indent (/app/emsdk/upstream/emscripten/third_party/terser/terser.js:5719:38)
#10 2924.9     at Object.with_block (/app/emsdk/upstream/emscripten/third_party/terser/terser.js:5753:9)
#10 2924.9     at print_braced (/app/emsdk/upstream/emscripten/third_party/terser/terser.js:6329:20)
#10 2928.1 Traceback (most recent call last):
#10 2928.1   File "/app/emsdk/upstream/emscripten/em++.py", line 14, in <module>
#10 2928.1     sys.exit(emcc.run(sys.argv))
#10 2928.1   File "/app/emsdk/upstream/emscripten/emcc.py", line 1154, in run
#10 2928.1     phase_post_link(options, state, wasm_target, wasm_target, target)
#10 2928.1   File "/usr/lib/python3.10/contextlib.py", line 79, in inner
#10 2928.1     return func(*args, **kwds)
#10 2928.1   File "/app/emsdk/upstream/emscripten/emcc.py", line 2687, in phase_post_link
#10 2928.1     phase_binaryen(target, options, wasm_target)
#10 2928.1   File "/usr/lib/python3.10/contextlib.py", line 79, in inner
#10 2928.1     return func(*args, **kwds)
#10 2928.1   File "/app/emsdk/upstream/emscripten/emcc.py", line 3331, in phase_binaryen
#10 2928.1     wasm2js = building.wasm2js(wasm2js_template,
#10 2928.1   File "/app/emsdk/upstream/emscripten/tools/building.py", line 1134, in wasm2js
#10 2928.1     temp = js_optimizer(temp, passes)
#10 2928.1   File "/app/emsdk/upstream/emscripten/tools/building.py", line 617, in js_optimizer
#10 2928.1     return js_optimizer.run(filename, passes)
#10 2928.1   File "/usr/lib/python3.10/contextlib.py", line 79, in inner
#10 2928.1     return func(*args, **kwds)
#10 2928.1   File "/app/emsdk/upstream/emscripten/tools/js_optimizer.py", line 398, in run
#10 2928.1     return run_on_js(filename, passes, extra_info=extra_info, just_split=just_split, just_concat=just_concat)
#10 2928.1   File "/app/emsdk/upstream/emscripten/tools/js_optimizer.py", line 301, in run_on_js
#10 2928.1     filenames = shared.run_multiple_processes(commands, route_stdout_to_temp_files_suffix='js_opt.jo.js')
#10 2928.1   File "/app/emsdk/upstream/emscripten/tools/shared.py", line 208, in run_multiple_processes
#10 2928.1     raise Exception('Subprocess %d/%d failed (%s)! (cmdline: %s)' % (idx + 1, len(commands), returncode_to_str(finished_process.returncode), shlex_join(commands[idx])))
#10 2928.1 Exception: Subprocess 10/23 failed (returned 1)! (cmdline: /app/emsdk/node/16.20.0_64bit/bin/node /app/emsdk/upstream/emscripten/tools/acorn-optimizer.js /tmp/tmpzcptkf_4.jsfunc_9.js minifyLocals minifyWhitespace last)
#10 2928.2 node:internal/fs/utils:347
#10 2928.2     throw err;
#10 2928.2     ^
#10 2928.2
#10 2928.2 Error: ENOENT: no such file or directory, open '/tmp/tmp_ibjrkwi.jsfunc_12.js'
#10 2928.2     at Object.openSync (node:fs:590:3)
#10 2928.2     at Object.readFileSync (node:fs:458:35)
#10 2928.2     at read (/app/emsdk/upstream/emscripten/tools/acorn-optimizer.js:20:13)
#10 2928.2     at Object.<anonymous> (/app/emsdk/upstream/emscripten/tools/acorn-optimizer.js:1834:15)
#10 2928.2     at Module._compile (node:internal/modules/cjs/loader:1196:14)
#10 2928.2     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
#10 2928.2     at Module.load (node:internal/modules/cjs/loader:1074:32)
#10 2928.2     at Function.Module._load (node:internal/modules/cjs/loader:909:12)
#10 2928.2     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
#10 2928.2     at node:internal/main/run_main_module:22:47 {
#10 2928.2   errno: -2,
#10 2928.2   syscall: 'open',
#10 2928.2   code: 'ENOENT',
#10 2928.2   path: '/tmp/tmp_ibjrkwi.jsfunc_12.js'
#10 2928.2 }
#10 2928.2 node:internal/fs/utils:347
#10 2928.2     throw err;
#10 2928.2     ^
#10 2928.2
#10 2928.2 Error: ENOENT: no such file or directory, open '/tmp/tmpotweghns.jsfunc_15.js'
#10 2928.2     at Object.openSync (node:fs:590:3)
#10 2928.2     at Object.readFileSync (node:fs:458:35)
#10 2928.2     at read (/app/emsdk/upstream/emscripten/tools/acorn-optimizer.js:20:13)
#10 2928.2     at Object.<anonymous> (/app/emsdk/upstream/emscripten/tools/acorn-optimizer.js:1834:15)
#10 2928.2     at Module._compile (node:internal/modules/cjs/loader:1196:14)
#10 2928.2     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
#10 2928.2     at Module.load (node:internal/modules/cjs/loader:1074:32)
#10 2928.2     at Function.Module._load (node:internal/modules/cjs/loader:909:12)
#10 2928.2     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
#10 2928.2     at node:internal/main/run_main_module:22:47 {
#10 2928.2   errno: -2,
#10 2928.2   syscall: 'open',
#10 2928.2   code: 'ENOENT',
#10 2928.2   path: '/tmp/tmpotweghns.jsfunc_15.js'
#10 2928.2 }
#10 2928.2 node:internal/fs/utils:347
#10 2928.2     throw err;
#10 2928.2     ^
#10 2928.2
#10 2928.2 Error: ENOENT: no such file or directory, open '/tmp/tmp6wty5jlv.jsfunc_14.js'
#10 2928.2     at Object.openSync (node:fs:590:3)
#10 2928.2     at Object.readFileSync (node:fs:458:35)
#10 2928.2     at read (/app/emsdk/upstream/emscripten/tools/acorn-optimizer.js:20:13)
#10 2928.2     at Object.<anonymous> (/app/emsdk/upstream/emscripten/tools/acorn-optimizer.js:1834:15)
#10 2928.2     at Module._compile (node:internal/modules/cjs/loader:1196:14)
#10 2928.2     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
#10 2928.2     at Module.load (node:internal/modules/cjs/loader:1074:32)
#10 2928.2     at Function.Module._load (node:internal/modules/cjs/loader:909:12)
#10 2928.2     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
#10 2928.2     at node:internal/main/run_main_module:22:47 {
#10 2928.2   errno: -2,
#10 2928.2   syscall: 'open',
#10 2928.2   code: 'ENOENT',
#10 2928.2   path: '/tmp/tmp6wty5jlv.jsfunc_14.js'
#10 2928.2 }
#10 2928.2 node:internal/fs/utils:347
#10 2928.2     throw err;
#10 2928.2     ^
#10 2928.2
#10 2928.2 Error: ENOENT: no such file or directory, open '/tmp/tmp8spozub4.jsfunc_13.js'
#10 2928.2     at Object.openSync (node:fs:590:3)
#10 2928.2     at Object.readFileSync (node:fs:458:35)
#10 2928.2     at read (/app/emsdk/upstream/emscripten/tools/acorn-optimizer.js:20:13)
#10 2928.2     at Object.<anonymous> (/app/emsdk/upstream/emscripten/tools/acorn-optimizer.js:1834:15)
#10 2928.2     at Module._compile (node:internal/modules/cjs/loader:1196:14)
#10 2928.2     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
#10 2928.2     at Module.load (node:internal/modules/cjs/loader:1074:32)
#10 2928.2     at Function.Module._load (node:internal/modules/cjs/loader:909:12)
#10 2928.2     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
#10 2928.2     at node:internal/main/run_main_module:22:47 {
#10 2928.2   errno: -2,
#10 2928.2   syscall: 'open',
#10 2928.2   code: 'ENOENT',
#10 2928.2   path: '/tmp/tmp8spozub4.jsfunc_13.js'
#10 2928.2 }
#10 2928.2 gmake[3]: *** [CMakeFiles/td_asmjs.dir/build.make:112: td_asmjs.js] Error 1
#10 2928.2 gmake[2]: *** [CMakeFiles/Makefile2:546: CMakeFiles/td_asmjs.dir/all] Error 2
#10 2928.2 gmake[1]: *** [CMakeFiles/Makefile2:553: CMakeFiles/td_asmjs.dir/rule] Error 2
#10 2928.2 gmake: *** [Makefile:296: td_asmjs] Error 2
#10 ERROR: executor failed running [/bin/sh -c ./build-td.sh]: exit code: 1

This happens when Building TDLib to asm.js

levlam commented 1 year ago

asm.js build is broken with the latest SDK. You can either switch to emsdk 3.1.1 as specified in README:

./emsdk install 3.1.1
./emsdk activate 3.1.1

and rebuild everything, or deploy only wasm build, which has been built correctly and is widely supported nowadays.

pfeux commented 1 year ago

I was able to build asm.js by making following changes

  1. When cloning esmdk git, I had to checkout tags v3.1.1 git checkout tags/3.1.1 -b emsdk_3.1.1 and
  2. use emsdk 3.1.1 specified in README i.e. ./emsdk install 3.1.1 and ./emsdk activate 3.1.1

What I noticed, the main branch of emsdk is using node v16.x.x, while tags v3.1.1 is using node v14.x.x

I am yet to run ./copy-tdlib.sh and ./build-tdweb.sh. I will close the issue once I finished running everything.

Thank you so much having lots of patience answering my queries.

levlam commented 1 year ago

The first step wasn't needed for me. The latest emsdk can install and activate "3.1.1" SDK without issues.

pfeux commented 1 year ago

I was able to build the tdweb successfully. Thanks so much @levlam