lwthiker / curl-impersonate

curl-impersonate: A special build of curl that can impersonate Chrome & Firefox
MIT License
3.69k stars 245 forks source link

cannot build from source on macbook air #130

Closed ntop001 closed 1 year ago

ntop001 commented 1 year ago

Sir, I follow the guide: https://github.com/lwthiker/curl-impersonate/blob/main/INSTALL.md#macos to build source code on MacBook air - m2 chip. All is ok until running gmake, here is the logs:

> gmake firefox-build
.... some other logs

curl -L -o nss-3.77.tar.gz https://ftp.mozilla.org/pub/security/nss/releases/NSS_3_77_RTM/src/nss-3.77-with-nspr-4.32.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 82.2M  100 82.2M    0     0  1059k      0  0:01:19  0:01:19 --:--:-- 1226k
tar xf nss-3.77.tar.gz
# Native build, use NSS' build script.
cd nss-3.77/nss
./build.sh -o --disable-tests --static --python=python3
# Hack for macOS: Remove dynamic libraries to force the linker to use the
# static ones when linking curl.
rm -Rf /Users/ntopliu/workspace/GithubProjects/curl-impersonate/build/nss-3.77/dist/Release/lib/*.dylib
NSPR [1/5] configure ...
NSPR [2/5] make ...
NSPR [3/5] NOT building tests
NSPR [4/5] NOT running tests
NSPR [5/5] install ...
Building NSS requires an installation of gyp: https://gyp.gsrc.io/
gmake: *** [Makefile:211: /Users/ntop/workspace/GithubProjects/curl-impersonate/build/nss-3.77/dist/Release/lib/libnss_static.a] Error 3

I searched the directory nss-3.77/dist/Release/lib/ there is no libnss_static.a :

libnspr4.a     libnspr4.dylib libplc4.a      libplc4.dylib  libplds4.a     libplds4.dylib pkgconfig

I don't know what happened and how can I fix it.

I also installed the gyp.

pip3 install gyp-next
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: gyp-next in /Users/ntopliu/Library/Python/3.9/lib/python/site-packages (0.4.0)
WARNING: You are using pip version 21.2.4; however, version 22.3.1 is available.
You should consider upgrading via the '/Applications/Xcode.app/Contents/Developer/usr/bin/python3 -m pip install --upgrade pip' command.
ntop001 commented 1 year ago

It seems pip3 install gyp-next will not install gyp command(only install packages), use pipx install gyp-next will install gyp command, But it still don't work:

rm -Rf /Users/ntopliu/workspace/GithubProjects/curl-impersonate/build/nss-3.77/dist/Release/lib/*.dylib
NSPR [1/5] configure ...
NSPR [2/5] make ...
NSPR [3/5] NOT building tests
NSPR [4/5] NOT running tests
NSPR [5/5] install ...
gmake: *** [Makefile:211: /Users/ntop/workspace/GithubProjects/curl-impersonate/build/nss-3.77/dist/Release/lib/libnss_static.a] Error 1

Still can not find libnss_static.a file at the path.

lwthiker commented 1 year ago

Hi,

Unfortunately I don't have access to a MacBook at the moment. Can you please run the following steps to help me understand the problem?

  1. Run the configure script
  2. Edit the Makefile that it creates. Change the following line:
    ./build.sh -o --disable-tests --static --python=python3

    to

    ./build.sh -v -o --disable-tests --static --python=python3

    (add the -v flag)

  3. Try to build again, and attach the error message that you get
ntop001 commented 1 year ago

@lwthiker Sir, here is the log:

tar xf nss-3.77.tar.gz
# Native build, use NSS' build script.
cd nss-3.77/nss
./build.sh -v -o --disable-tests --static --python=python3
# Hack for macOS: Remove dynamic libraries to force the linker to use the
# static ones when linking curl.
rm -Rf /Users/ntopliu/workspace/GithubProjects/curl-impersonate/build/nss-3.77/dist/Release/lib/*.dylib
run_scanbuild gyp -f ninja --depth=/Users/ntopliu/workspace/GithubProjects/curl-impersonate/build/nss-3.77/nss --generator-output=. -Ddisable_tests=1 -Dstatic_libs=1 -Dpython=python3 -Dtarget_arch=arm64 -Denable_sslkeylogfile=1 -Dnss_dist_dir=/Users/ntopliu/workspace/GithubProjects/curl-impersonate/build/nss-3.77/dist -Dnss_dist_obj_dir=/Users/ntopliu/workspace/GithubProjects/curl-impersonate/build/nss-3.77/dist/Release -Dnspr_include_dir=/Users/ntopliu/workspace/GithubProjects/curl-impersonate/build/nss-3.77/dist/Release/include/nspr -Dnspr_lib_dir=/Users/ntopliu/workspace/GithubProjects/curl-impersonate/build/nss-3.77/dist/Release/lib /Users/ntopliu/workspace/GithubProjects/curl-impersonate/build/nss-3.77/nss/nss.gyp
Exception: invalid mode: 'rU'
Traceback (most recent call last):
  File "/Users/ntopliu/.local/pipx/venvs/gyp-next/lib/python3.11/site-packages/gyp/input.py", line 534, in CallLoadTargetBuildFile
    result = LoadTargetBuildFile(
             ^^^^^^^^^^^^^^^^^^^^
  File "/Users/ntopliu/.local/pipx/venvs/gyp-next/lib/python3.11/site-packages/gyp/input.py", line 411, in LoadTargetBuildFile
    build_file_data = LoadOneBuildFile(
                      ^^^^^^^^^^^^^^^^^
  File "/Users/ntopliu/.local/pipx/venvs/gyp-next/lib/python3.11/site-packages/gyp/input.py", line 239, in LoadOneBuildFile
    build_file_contents = open(build_file_path, "rU").read()
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid mode: 'rU'

gmake: *** [Makefile:211: /Users/ntopliu/workspace/GithubProjects/curl-impersonate/build/nss-3.77/dist/Release/lib/libnss_static.a] Error 1
lwthiker commented 1 year ago

Looks like a problem with gyp. It doesn't work with Python 3.11. I reproduced the same error on Debian when using the latest Python version.

As a temporary solution try installing Python 3.10 instead. For a permanent fix, I'll have to figure something out.

ntop001 commented 1 year ago

@lwthiker Yes, sir. I'll try later.

ntop001 commented 1 year ago

@lwthiker Sir, good news, I have successfully build it. This is what I do:

Go to /Users/ntopliu/.local/pipx/venvs/gyp-next/lib/python3.11/site-packages/gyp/input.py" file, change if sys.platform == "zos": to if PY3 or sys.platform == "zos":. then the python will build(fix the rU error).

Then I come cross another problem: env: python: No such file or directory. It seems no python command(but I have python3 installed by system), I create a soft-link: ln -s /usr/bin/python3 /usr/bin/python , this'll fix the problem.

Then I come another another problem: python: error: Failed to locate 'python', this problem have something to do with the Xcode, after some searching, found this: https://stackoverflow.com/questions/72345515/mac-os12-4-python-error-failed-to-locate-python. just created another soft-link:

ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /Applications/Xcode.app/Contents/Developer/usr/bin/python

Then all is fine!!! It works!!! It seems all the fucking things come from Mac OS and it's default python installation.

caffeinejolt commented 1 year ago

I am having the same problem on AlmaLinux 8. make firefox-build error output. I have to compile due to glibc 2.2 use.

Native build, use NSS' build script. cd nss-3.77/nss ./build.sh -o --disable-tests --static --python=python3 Hack for macOS: Remove dynamic libraries to force the linker to use the static ones when linking curl. rm -Rf curl-impersonate/build/nss-3.77/dist/Release/lib/*.dylib NSPR [1/5] configure ... NSPR [2/5] make ... NSPR [3/5] NOT building tests NSPR [4/5] NOT running tests NSPR [5/5] install ... make: *** [Makefile:211: curl-impersonate/build/nss-3.77/dist/Release/lib/libnss_static.a] Error 245