Opened 8 months ago

Last modified 7 months ago

#68185 new defect

rust: source build fails when running under rosetta 2

Reported by: lukaso (Lukas Oberhuber) Owned by:
Priority: Normal Milestone:
Component: ports Version:
Keywords: Cc: mascguy (Christopher Nielsen)
Port: rust

Description

When I look to build an x86_64 version of rust under rosetta arch -x86-64 /bin/zsh, it fails with:

:info:build DYLD_LIBRARY_PATH="/Users/lukasoberhuber/macports-gimp3-x86_64/var/macports/build/_Users_lukasoberhuber_macports-gimp3-x86_64_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_rust/rust/work/rustc-1.71.1-src/build/x86_64-apple-darwin/stage1/lib" "/Users/lukasoberhuber/macports-gimp3-x86_64/var/macports/build/_Users_lukasoberhuber_macports-gimp3-x86_64_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_rust/rust/work/rustc-1.71.1-src/build/x86_64-apple-darwin/stage1/bin/rustc" "-vV" "-Wrust_2018_idioms" "-Wunused_lifetimes" "-Wsemicolon_in_expressions_from_macros" "-Dwarnings" "-Clinker=/Users/lukasoberhuber/macports-gimp3-x86_64/var/macports/build/_Users_lukasoberhuber_macports-gimp3-x86_64_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_rust/rust/work/compwrap/ld/usr/bin/clang" "-Zunstable-options" "--check-cfg=values(bootstrap)" "--remap-path-prefix" "/Users/lukasoberhuber/macports-gimp3-x86_64/var/macports/build/_Users_lukasoberhuber_macports-gimp3-x86_64_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_rust/rust/work=/Users/lukasoberhuber/macports-gimp3-x86_64/libexec/rust/src" "-Z" "force-unstable-if-unmarked"
:info:build -------------
:info:build --- stderr
:info:build <jemalloc>: Error allocating TSD
:info:build rustc exited with signal: 6 (SIGABRT)

Why would I want to do this relatively exotic build? Because Circle CI is getting ready to get rid of all Intel build bots and so this is how I will have to build the intel version.

This would not be an issue if macports could use pre-built binaries for rust when building in a custom location and without sudo, but I don't think that's how it work.

Attachments (1)

rust_main.log (9.1 MB) - added by lukaso (Lukas Oberhuber) 8 months ago.
Built on M1 Mac but with terminal in rosetta mode

Change History (7)

Changed 8 months ago by lukaso (Lukas Oberhuber)

Attachment: rust_main.log added

Built on M1 Mac but with terminal in rosetta mode

comment:1 Changed 8 months ago by lukaso (Lukas Oberhuber)

comment:2 Changed 7 months ago by lukaso (Lukas Oberhuber)

If we want to work around this, this command will detect (return 1) if running under rosetta 2: sysctl -n sysctl.proc_translated.

I'm not sure how to do an if based on running a command in a Portfile or I'd give it a go.

comment:3 Changed 7 months ago by mascguy (Christopher Nielsen)

Cc: mascguy added

comment:4 Changed 7 months ago by lukaso (Lukas Oberhuber)

I have tried with adding that check to my Portfile. Rust now builds successfully.

Here's the specific bit:

if { ${os.platform} eq "darwin" && ${os.major} > 14 } {
    # check if running in rosetta2 and don't set jemalloc if so
    try {
        set in_rosetta2 [exec sysctl -n sysctl.proc_translated]
        if { ${in_rosetta2} == 0 } {
            configure.args-append   --set=rust.jemalloc
            ui_debug "proc_translated = 0. Enabling jemalloc."
        } else {
            ui_debug "proc_translated = 1. Disabling jemalloc."
            depends_build-append        port:libatomic_ops
        }
    } catch {
        ui_debug "proc_translated errored. Disabling jemalloc."
        depends_build-append        port:libatomic_ops
        # Handle non-zero return of proc_translated gracefully, optionally log the error.
    }
    if { ${os.arch} eq "arm" } {
        configure.args-append   --set=rust.jemalloc
        # specify the number of significant virtual address bits in jmalloc
        # the configure script calls cpuid, but it does not work properly on Rosetta 2
        # see https://github.com/jemalloc/jemalloc/issues/1997#issuecomment-1041589117
        build.env.x86_64-append     JEMALLOC_SYS_WITH_LG_VADDR=48
        destroot.env.x86_64-append  JEMALLOC_SYS_WITH_LG_VADDR=48
    }
}

I have run into a different error later in the build, but this is a start.

comment:5 Changed 7 months ago by lukaso (Lukas Oberhuber)

OK, actually, the different error appears to be related to XCode 15 rather than anything related to rosetta2. So once that is fixed, building under rosetta2 should work.

comment:6 Changed 7 months ago by lukaso (Lukas Oberhuber)

Note: See TracTickets for help on using tickets.