Compile rustc for a custom target

Hi everyone,

I am working actually on my Linux distribution. I did a package manager able to build a Linux system completely from scratch from the source.

I am just facing a small problem. I need to compile rustc for a custom target.
The target I have on the system is: x86_64-horizon-linux-gnu

How should I proceed ? I guess I need to change something in the file config.toml, but after lot of try, I don't get the result I want...

This is the script called by my package manager (even you don't know the API, should be easy to understand):

class Target < ISM::Software

    def prepare
        super

        configData = <<-CODE
        changelog-seen = 2

        [llvm]
        targets = "X86"
        link-shared = true

        [build]
        full-bootstrap = true
        docs = false
        extended = true
        locked-deps = true
        tools = ["cargo", "clippy", "rustdoc", "rustfmt"]
        vendor = true

        [install]
        prefix = "/usr"
        docdir = "share/doc/rustc-1.71.1"

        [rust]
        channel = "stable"

        [target.#{Ism.settings.systemTarget}]
        llvm-config = "/usr/bin/llvm-config"
        CODE
        fileWriteData("#{buildDirectoryPath}/config.toml",configData)
    end
    
    def build
        super

        runPythonCommand(   arguments:      "./x.py build",
                            path:           buildDirectoryPath,
                            environment:    {"LIBSSH2_SYS_USE_PKG_CONFIG" => "1"})
    end
    
    def prepareInstallation
        super

        runPythonCommand(   arguments:      "./x.py install",
                            path:           buildDirectoryPath,
                            environment:    {   "DESTDIR" => "#{builtSoftwareDirectoryPath}#{Ism.settings.rootPath}",
                                                "LIBSSH2_SYS_USE_PKG_CONFIG" => "1"})

        deleteAllFilesRecursivelyFinishing( path:       "#{builtSoftwareDirectoryPath}#{Ism.settings.rootPath}",
                                            extensions: ["old"])
    end

end

This is my project page by the way: https://github.com/Fulgurance/ISM

(Horizon will be my linux system name)

While you were absolutely correct to post this here, in this particular case I think you may have a higher probability of getting a useful answer on IRLO.

The reason for that is that adding a new target is more akin to development of the Rust language itself rather than using Rust (even though that is ultimately the point).

Okay got it. It's done. Thanks a lot :grin:

As I understand it, Rust uses unknown always, instead of for example pc or whatever vanity name different distros want to use. Unlike GCC etc, the target triplet is considered as a single string that has to match exactly. So this sort of customisation simply isn't supported.

Okay, so in that case. I have a question. How can I then build properly firefox. Because of this, I get an error normally I don't have. Firefox can't find cmath

 1:29.01   exit status: 0
 1:29.01   running: "/usr/bin/clang" "-O1" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=x86_64-unknown-linux-gnu" "-std=gnu99" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/system_wrappers" "-include" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/config/gcc_hidden.h" "-U_FORTIFY_SOURCE" "-D_FORTIFY_SOURCE=2" "-fstack-protector-strong" "-fstack-clash-protection" "-DNDEBUG=1" "-DTRIMMED=1" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/toolkit/library/rust" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/toolkit/library/rust" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/include" "-I/usr/include/nspr" "-I/usr/include/nss" "-I/usr/include/nspr" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/include/nss" "-I/usr/include/libpng16" "-I/usr/include/pixman-1" "-include" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/mozilla-config.h" "-DMOZILLA_CLIENT" "-fPIC" "-ffunction-sections" "-fdata-sections" "-fno-math-errno" "-pthread" "-pipe" "-O2" "-fomit-frame-pointer" "-funwind-tables" "-Wno-error=tautological-type-limit-compare" "-Wno-range-loop-analysis" "-Wno-error=deprecated-declarations" "-Wno-error=array-bounds" "-Wno-error=free-nonheap-object" "-Wno-error=atomic-alignment" "-Wno-error=deprecated-builtins" "-Wno-psabi" "-Wno-error=builtin-macro-redefined" "-Wno-unknown-warning-option" "-fno-strict-aliasing" "-ffp-contract=off" "-DMOZILLA_CONFIG_H" "-I" "glsl-optimizer/include" "-I" "glsl-optimizer/src/mesa" "-I" "glsl-optimizer/src/mapi" "-I" "glsl-optimizer/src/compiler" "-I" "glsl-optimizer/src/compiler/glsl" "-I" "glsl-optimizer/src/gallium/auxiliary" "-I" "glsl-optimizer/src/gallium/include" "-I" "glsl-optimizer/src" "-I" "glsl-optimizer/src/util" "-D__STDC_FORMAT_MACROS" "-D_GNU_SOURCE" "-DHAVE_ENDIAN_H" "-DHAVE_PTHREAD" "-DHAVE_TIMESPEC_GET" "-DMOZ_INCLUDE_MOZALLOC_H" "-Dmozilla_throw_gcc_h" "-o" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/release/build/glslopt-ce80c9358cf233fd/out/glsl-optimizer/src/compiler/shader_enums.o" "-c" "glsl-optimizer/src/compiler/shader_enums.c"
 1:29.01   exit status: 0
 1:29.01   AR_x86_64-unknown-linux-gnu = None
 1:29.01   AR_x86_64_unknown_linux_gnu = Some("/usr/bin/llvm-ar")
 1:29.01   running: ZERO_AR_DATE="1" "/usr/bin/llvm-ar" "cq" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/release/build/glslopt-ce80c9358cf233fd/out/libmesa.a" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/release/build/glslopt-ce80c9358cf233fd/out/glsl-optimizer/src/mesa/program/dummy_errors.o" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/release/build/glslopt-ce80c9358cf233fd/out/glsl-optimizer/src/mesa/program/symbol_table.o" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/release/build/glslopt-ce80c9358cf233fd/out/glsl-optimizer/src/mesa/main/extensions_table.o" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/release/build/glslopt-ce80c9358cf233fd/out/glsl-optimizer/src/compiler/shader_enums.o"
 1:29.01   exit status: 0
 1:29.01   running: "/usr/bin/llvm-ar" "s" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/release/build/glslopt-ce80c9358cf233fd/out/libmesa.a"
 1:29.01   exit status: 0
 1:29.01   cargo:rustc-link-lib=static=mesa
 1:29.01   cargo:rustc-link-search=native=/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/release/build/glslopt-ce80c9358cf233fd/out
 1:29.01   TARGET = Some("x86_64-unknown-linux-gnu")
 1:29.01   OPT_LEVEL = Some("1")
 1:29.01   HOST = Some("x86_64-unknown-linux-gnu")
 1:29.01   CXX_x86_64-unknown-linux-gnu = None
 1:29.01   CXX_x86_64_unknown_linux_gnu = Some("/usr/bin/clang++")
 1:29.01   CXXFLAGS_x86_64-unknown-linux-gnu = None
 1:29.01   CXXFLAGS_x86_64_unknown_linux_gnu = Some(" -I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/stl_wrappers -I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/system_wrappers -include /sources/WebBrowsers-Main/Firefox/115.2.0/Sources/config/gcc_hidden.h -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fstack-clash-protection -DNDEBUG=1 -DTRIMMED=1 -I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/toolkit/library/rust -I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/toolkit/library/rust -I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/include -I/usr/include/nspr -I/usr/include/nss -I/usr/include/nspr -I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/include/nss -I/usr/include/libpng16 -I/usr/include/pixman-1 -DMOZILLA_CLIENT -include /sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/mozilla-config.h -fno-sized-deallocation -fno-aligned-new -fno-exceptions -fPIC -fno-rtti -ffunction-sections -fdata-sections -fno-exceptions -fno-math-errno -pthread -pipe -O2 -fomit-frame-pointer -funwind-tables -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-error=deprecated -Wno-error=deprecated-anon-enum-enum-conversion -Wno-error=deprecated-enum-enum-conversion -Wno-error=deprecated-pragma -Wno-error=deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -fno-strict-aliasing -ffp-contract=off -DMOZILLA_CONFIG_H")
 1:29.01   CRATE_CC_NO_DEFAULTS = None
 1:29.01   DEBUG = Some("false")
 1:29.01   running: "/usr/bin/clang++" "-O1" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=x86_64-unknown-linux-gnu" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/stl_wrappers" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/system_wrappers" "-include" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/config/gcc_hidden.h" "-U_FORTIFY_SOURCE" "-D_FORTIFY_SOURCE=2" "-fstack-protector-strong" "-fstack-clash-protection" "-DNDEBUG=1" "-DTRIMMED=1" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/toolkit/library/rust" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/toolkit/library/rust" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/include" "-I/usr/include/nspr" "-I/usr/include/nss" "-I/usr/include/nspr" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/include/nss" "-I/usr/include/libpng16" "-I/usr/include/pixman-1" "-DMOZILLA_CLIENT" "-include" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/mozilla-config.h" "-fno-sized-deallocation" "-fno-aligned-new" "-fno-exceptions" "-fPIC" "-fno-rtti" "-ffunction-sections" "-fdata-sections" "-fno-exceptions" "-fno-math-errno" "-pthread" "-pipe" "-O2" "-fomit-frame-pointer" "-funwind-tables" "-Wno-error=tautological-type-limit-compare" "-Wno-invalid-offsetof" "-Wno-range-loop-analysis" "-Wno-error=deprecated" "-Wno-error=deprecated-anon-enum-enum-conversion" "-Wno-error=deprecated-enum-enum-conversion" "-Wno-error=deprecated-pragma" "-Wno-error=deprecated-this-capture" "-Wno-inline-new-delete" "-Wno-error=deprecated-declarations" "-Wno-error=array-bounds" "-Wno-error=free-nonheap-object" "-Wno-error=atomic-alignment" "-Wno-error=deprecated-builtins" "-Wno-psabi" "-Wno-error=builtin-macro-redefined" "-Wno-unknown-warning-option" "-fno-strict-aliasing" "-ffp-contract=off" "-DMOZILLA_CONFIG_H" "-I" "glsl-optimizer/include" "-I" "glsl-optimizer/src/mesa" "-I" "glsl-optimizer/src/mapi" "-I" "glsl-optimizer/src/compiler" "-I" "glsl-optimizer/src/compiler/glsl" "-I" "glsl-optimizer/src/gallium/auxiliary" "-I" "glsl-optimizer/src/gallium/include" "-I" "glsl-optimizer/src" "-I" "glsl-optimizer/src/util" "-D__STDC_FORMAT_MACROS" "-D_GNU_SOURCE" "-DHAVE_ENDIAN_H" "-DHAVE_PTHREAD" "-DHAVE_TIMESPEC_GET" "-DMOZ_INCLUDE_MOZALLOC_H" "-Dmozilla_throw_gcc_h" "-o" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/release/build/glslopt-ce80c9358cf233fd/out/glsl-optimizer/src/compiler/glsl_types.o" "-c" "glsl-optimizer/src/compiler/glsl_types.cpp"
 1:29.01   cargo:warning=In file included from glsl-optimizer/src/compiler/glsl_types.cpp:25:
 1:29.01   cargo:warning=In file included from glsl-optimizer/src/mesa/main/macros.h:35:
 1:29.01   cargo:warning=In file included from glsl-optimizer/src/util/u_math.h:42:
 1:29.01   cargo:warning=In file included from glsl-optimizer/include/c99_math.h:194:
 1:29.01   cargo:warning=In file included from /sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/stl_wrappers/cmath:62:
 1:29.01   cargo:warning=/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/system_wrappers/cmath:3:15: fatal error: 'cmath' file not found
 1:29.01   cargo:warning=#include_next <cmath>
 1:29.01   cargo:warning=              ^~~~~~~
 1:29.01   cargo:warning=1 error generated.
 1:29.01   exit status: 1
 1:29.02   --- stderr
 1:29.02   error occurred: Command "/usr/bin/clang++" "-O1" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=x86_64-unknown-linux-gnu" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/stl_wrappers" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/system_wrappers" "-include" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/config/gcc_hidden.h" "-U_FORTIFY_SOURCE" "-D_FORTIFY_SOURCE=2" "-fstack-protector-strong" "-fstack-clash-protection" "-DNDEBUG=1" "-DTRIMMED=1" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/toolkit/library/rust" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/toolkit/library/rust" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/include" "-I/usr/include/nspr" "-I/usr/include/nss" "-I/usr/include/nspr" "-I/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/dist/include/nss" "-I/usr/include/libpng16" "-I/usr/include/pixman-1" "-DMOZILLA_CLIENT" "-include" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/mozilla-config.h" "-fno-sized-deallocation" "-fno-aligned-new" "-fno-exceptions" "-fPIC" "-fno-rtti" "-ffunction-sections" "-fdata-sections" "-fno-exceptions" "-fno-math-errno" "-pthread" "-pipe" "-O2" "-fomit-frame-pointer" "-funwind-tables" "-Wno-error=tautological-type-limit-compare" "-Wno-invalid-offsetof" "-Wno-range-loop-analysis" "-Wno-error=deprecated" "-Wno-error=deprecated-anon-enum-enum-conversion" "-Wno-error=deprecated-enum-enum-conversion" "-Wno-error=deprecated-pragma" "-Wno-error=deprecated-this-capture" "-Wno-inline-new-delete" "-Wno-error=deprecated-declarations" "-Wno-error=array-bounds" "-Wno-error=free-nonheap-object" "-Wno-error=atomic-alignment" "-Wno-error=deprecated-builtins" "-Wno-psabi" "-Wno-error=builtin-macro-redefined" "-Wno-unknown-warning-option" "-fno-strict-aliasing" "-ffp-contract=off" "-DMOZILLA_CONFIG_H" "-I" "glsl-optimizer/include" "-I" "glsl-optimizer/src/mesa" "-I" "glsl-optimizer/src/mapi" "-I" "glsl-optimizer/src/compiler" "-I" "glsl-optimizer/src/compiler/glsl" "-I" "glsl-optimizer/src/gallium/auxiliary" "-I" "glsl-optimizer/src/gallium/include" "-I" "glsl-optimizer/src" "-I" "glsl-optimizer/src/util" "-D__STDC_FORMAT_MACROS" "-D_GNU_SOURCE" "-DHAVE_ENDIAN_H" "-DHAVE_PTHREAD" "-DHAVE_TIMESPEC_GET" "-DMOZ_INCLUDE_MOZALLOC_H" "-Dmozilla_throw_gcc_h" "-o" "/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/firefox-build-dir/release/build/glslopt-ce80c9358cf233fd/out/glsl-optimizer/src/compiler/glsl_types.o" "-c" "glsl-optimizer/src/compiler/glsl_types.cpp" with args "clang++" did not execute successfully (status code exit status: 1).
 1:29.02 warning: build failed, waiting for other jobs to finish...
 1:34.20 devtools/platform
 1:34.72 devtools/shared/heapsnapshot
 1:36.32 docshell/base
 1:39.69 docshell/base/timeline
 1:41.19 docshell/build
 1:41.20 docshell/shistory
 1:41.24 dom/abort
 1:41.25 dom/animation
 1:41.26 dom/audiochannel
 1:41.54 dom/base
 1:42.20 dom/battery
 1:43.53 make[4]: *** [/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/config/makefiles/rust.mk:441: force-cargo-library-build] Error 101
 1:43.53 make[3]: *** [/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/config/recurse.mk:72: toolkit/library/rust/target] Error 2
 1:43.54 make[3]: *** Waiting for unfinished jobs....
 2:37.71 make[2]: *** [/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/config/recurse.mk:34: compile] Error 2
 2:37.71 make[1]: *** [/sources/WebBrowsers-Main/Firefox/115.2.0/Sources/config/rules.mk:361: default] Error 2
 2:37.71 make: *** [client.mk:60: build] Error 2
 2:37.73 9 compiler warnings present.
[!] Failed to run python ./mach build in /sources/WebBrowsers-Main/Firefox/115.2.0/Sources// with given environment MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=none MOZBUILD_STATE_PATH=mozbuild with the loaded environment file

That I don't know. I have never attempted to mix vanity triplets with default ones.

You could perhaps check what other distros with vanity triplets do. Arch Linux appears to carry patches for example: Arch Linux / Packaging / Packages / rust ยท GitLab

I don't know where to find Debian packages etc, but they likely have similar things going on.

In general I would suggest avoiding custom triplets, it just creates unnecessary pain for you and your users.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.