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

libc does not seem to respect the CC environment variable #3603

Open
molysgaard opened this issue Feb 29, 2024 · 0 comments
Open

libc does not seem to respect the CC environment variable #3603

molysgaard opened this issue Feb 29, 2024 · 0 comments
Labels
C-bug Category: bug

Comments

@molysgaard
Copy link

To reproduce:

  • Be on a platform that does not have the cc binary, but does have eg. gcc installed
  • Compile using CC=gcc cargo build
  • Observe the following error:
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: could not compile `libc` (build script) due to 1 previous error

Correct behaviour should be that the build.rs script should honor the CC environment variable
and use that to link.

This is explicitly a problem when trying to get reproducible builds in systems like GUIX or (I presume, NIX).

Guix example

; working-developer-shell.scm
(use-modules (gnu)
             (gnu packages commencement)
	     (guix)
	     (guix packages)
	     (guix build-system trivial)
	     (guix licenses)
             )

(define base-manifest (specifications->manifest
  '(
    "rust@1.73.0"
    "rust-cargo@0.74"
    "gcc-toolchain"
    "coreutils"
    )))

(define-public custom-cc
  (package
    (name "custom-cc")
    (version "1.0")
    (source #f)
    (build-system trivial-build-system)
    (arguments
     `(#:modules ((guix build utils))
       #:builder (begin
                   (use-modules (guix build utils))
                   (let* ((out (assoc-ref %outputs "out"))
                          (bin (string-append out "/bin"))
                          ;; Adjust the path to the gcc binary as necessary.
                          (gcc-path (string-append (assoc-ref %build-inputs "gcc-toolchain") "/bin/gcc")))
                     (mkdir-p bin)
                     (symlink gcc-path (string-append bin "/cc"))))))
    (inputs
     `(("gcc-toolchain", gcc-toolchain)))
    (synopsis "Custom package providing a cc symlink to gcc")
    (description "This package installs a symlink named 'cc' in its bin output, which points to the gcc binary in the gcc-toolchain package.")
    (home-page "https://example.com")
    (license gpl3)))


(define custom-cc-manifest (manifest (list (package->manifest-entry custom-cc))))

(concatenate-manifests (list base-manifest custom-cc-manifest))
; broken-developer-shell.scm
(use-modules (gnu)
             (gnu packages commencement)
	     (guix)
	     (guix packages)
	     (guix build-system trivial)
	     (guix licenses)
             )

(define base-manifest (specifications->manifest
  '(
    "rust@1.73.0"
    "rust-cargo@0.74"
    "gcc-toolchain"
    "coreutils"
    )))

base-manifest

Broken example using guix

git clone https://github.com/rust-lang/libc.git
cd libc
guix environment -m ../broken-developer-shell.scm --pure
CC=gcc cargo build

Working example using guix

In this example, we add a symlink named cc in our PATH that points to gcc.

git clone https://github.com/rust-lang/libc.git
cd libc
guix environment -m ../working-developer-shell.scm --pure
cargo build
@molysgaard molysgaard added the C-bug Category: bug label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

1 participant