rust-cross / cargo-zigbuild

Compile Cargo project with zig as linker
MIT License
1.55k stars 57 forks source link

Fails when path contains a space #134

Closed konstin closed 1 year ago

konstin commented 1 year ago

When the path contains spaces, the generated exec call in the wrapper script will split the path and then fail to build:

https://github.com/rust-cross/cargo-zigbuild/blob/36f6b83eb710ae01e9ad00f11316d9c795394c16/src/zig.rs#L879

Complete log:

$ cd /tmp/
$ mkdir "my dir"
$ cd my\ dir/
$ cargo new my-project
     Created binary (application) `my-project` package
$ cd my-project/
$ virtualenv -p 3.11 .venv
created virtual environment CPython3.11.2.final.0-64 in 124ms
  creator CPython3Posix(dest=/tmp/my dir/my-project/.venv, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/konsti/.local/share/virtualenv)
    added seed packages: pip==23.1.2, setuptools==67.7.2, wheel==0.40.0
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
$ . .venv/bin/activate
$ pip install cargo-zigbuild
Collecting cargo-zigbuild
  Using cached cargo_zigbuild-0.16.7-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (993 kB)
Collecting ziglang>=0.9.0 (from cargo-zigbuild)
  Using cached ziglang-0.10.1.post1-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.musllinux_1_1_x86_64.whl (74.5 MB)
Installing collected packages: ziglang, cargo-zigbuild
Successfully installed cargo-zigbuild-0.16.7 ziglang-0.10.1.post1
$ cargo add ring
    Updating crates.io index
      Adding ring v0.16.20 to dependencies.
             Features:
             + alloc
             + dev_urandom_fallback
             + once_cell
             - internal_benches
             - slow_tests
             - std
             - test_logging
             - wasm32_c
$ cargo-zigbuild build --target aarch64-linux-android # pick any non-native target
   Compiling libc v0.2.144
   Compiling cc v1.0.79
   Compiling once_cell v1.17.1
   Compiling spin v0.5.2
   Compiling untrusted v0.7.1
   Compiling ring v0.16.20
error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/tmp/my dir/my-project/target/debug/build/ring-ea1019ee7dfe5dec/build-script-build` (exit status: 101)
  --- stdout
  OPT_LEVEL = Some("0")
  TARGET = Some("aarch64-linux-android")
  HOST = Some("x86_64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_aarch64-linux-android
  CC_aarch64-linux-android = None
  cargo:rerun-if-env-changed=CC_aarch64_linux_android
  CC_aarch64_linux_android = Some("/home/konsti/.cache/cargo-zigbuild/0.16.7/zigcc-aarch64-linux-android.sh")
  cargo:rerun-if-env-changed=CFLAGS_aarch64-linux-android
  CFLAGS_aarch64-linux-android = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_linux_android
  CFLAGS_aarch64_linux_android = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("neon")

  --- stderr
  running "/home/konsti/.cache/cargo-zigbuild/0.16.7/zigcc-aarch64-linux-android.sh" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-2" "-fno-omit-frame-pointer" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-DNDEBUG" "-c" "-o/tmp/my dir/my-project/target/aarch64-linux-android/debug/build/ring-5989544e711c64f2/out/aesv8-armx-linux64.o" "/home/konsti/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesv8-armx-linux64.S"
  /home/konsti/.cache/cargo-zigbuild/0.16.7/zigcc-aarch64-linux-android.sh: 2: exec: /tmp/my: not found
  thread 'main' panicked at 'execution failed', /home/konsti/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/build.rs:656:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Commands only:

cd /tmp/
mkdir "my dir"
cd my\ dir/
cargo new my-project
cd my-project/
virtualenv -p 3.11 .venv
. .venv/bin/activate
pip install cargo-zigbuild
cargo add ring
cargo-zigbuild build --target aarch64-linux-android # pick any non-native target