Compiling rust package using cc linker from a custom location


#1

Hi,

I’m trying to compile a Rust package using the C compiler provided using the conda package manager.

conda allows you to specify a compiler that is needed for the build recipe in the meta.yaml file. For example:

requirements:
  host:
  build:
    - {{ compiler('c') }}
  run:

During the build stage, the compiler is installed in a custom location and the appropriate environment variables are set:

+ADDR2LINE=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-addr2line
+AR=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-ar
+AS=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-as
+CXXFILT=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-c++filt
+ELFEDIT=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-elfedit
+GPROF=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-gprof
+HOST=x86_64-conda_cos6-linux-gnu
+LD_GOLD=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-ld.gold
+LD=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-ld
+NM=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-nm
+OBJCOPY=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-objcopy
+OBJDUMP=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-objdump
+RANLIB=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-ranlib
+READELF=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-readelf
+SIZE=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-size
+STRINGS=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-strings
+STRIP=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-strip
INFO: activate-gcc_linux-64.sh made the following environmental changes:
+CC=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-cc
+CFLAGS=-march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -I/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/include -fdebug-prefix-map=${SRC_DIR}=/usr/local/src/conda/${PKG_NAME}-${PKG_VERSION} -fdebug-prefix-map=${PREFIX}=/usr/local/src/conda-prefix
+CPPFLAGS=-DNDEBUG -D_FORTIFY_SOURCE=2 -O2
+CPP=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-cpp
+DEBUG_CFLAGS=-march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-all -fno-plt -Og -g -Wall -Wextra -fvar-tracking-assignments -pipe -I/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/include -fdebug-prefix-map=${SRC_DIR}=/usr/local/src/conda/${PKG_NAME}-${PKG_VERSION} -fdebug-prefix-map=${PREFIX}=/usr/local/src/conda-prefix
+DEBUG_CPPFLAGS=-D_DEBUG -D_FORTIFY_SOURCE=2 -Og
+GCC_AR=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-gcc-ar
+GCC_NM=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-gcc-nm
+GCC=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-gcc
+GCC_RANLIB=/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-gcc-ranlib
+LDFLAGS=-Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-rpath,/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib -L/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib

This works well when compiling C / C++ libraries. However, rustc does not seem to use the environment variables, and fails with a error: linker `cc` not found error. The complete build log can be found here: https://gitlab.com/kimlab/uniparc_xml_parser/-/jobs/53928151.

Is there any way to make rust use cc that my $CC environment variable refers to (/opt/conda/conda-bld/uniparc_xml_parser_1519326308747/_build_env/bin/x86_64-conda_cos6-linux-gnu-cc)?

Thank you!


#2

This can be configured in .cargo/config: https://doc.rust-lang.org/cargo/reference/config.html.

Note that you can also use environment variables to control that state, so you can set CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER rather than having to make a file.


#3

Thank you! :slight_smile: