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

Unable to find crate proc_macro on musl target #40174

Closed
golddranks opened this issue Mar 1, 2017 · 26 comments
Closed

Unable to find crate proc_macro on musl target #40174

golddranks opened this issue Mar 1, 2017 · 26 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. O-musl Target: The musl libc T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@golddranks
Copy link
Contributor

Using procedural derive macros on musl seems to work just fine for the most of the cases, but there is one pitfall; in some cases like this dtolnay/proc-macro-hack#6 build fails because not only the crate that implements the macro (crate marked with proc-macro = true), but also another, normal crate links to the proc_macro crate. "Normal" crates are unable to find proc_macro when built on musl target:

Compiling proc-macro-hack v0.3.0
error[E0463]: can't find crate for `proc_macro`
 --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro-hack-0.3.0/src/lib.rs:1:1
  |
1 | extern crate proc_macro;
  | ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

error: Could not compile `proc-macro-hack`.
@alexcrichton
Copy link
Member

Yes this is currently intentional. The proc_macro crate is only a dynamic library which the musl target currently doesn't support. I unfortunately don't think this will be easy to fix...

@golddranks
Copy link
Contributor Author

I understand why the proc macro crates need to be dynamic: they are loaded and run dynamically by the compiler. However what I don't understand is why the proc_macro crate isn't allowed to be linked both dynamically and statically? I'd imagine someone may want to use the types defined in proc_macro in some helper crate, outside the dynamically linked macro crate, as is the case here.

@golddranks
Copy link
Contributor Author

Is there some technical hurdle that makes it hard to do, or is it just not done because it's such a minor case?

@golddranks
Copy link
Contributor Author

golddranks commented Mar 1, 2017

The simplest test for this seems to be:

test.rs with just single line:

extern crate proc_macro;

build with (succeeds):

rustc test.rs --crate-type lib

and with (fails):

rustc test.rs --crate-type lib --target=x86_64-unknown-linux-musl

When RUST_LOG=info is enabled, the library probes can be seen.

@golddranks
Copy link
Contributor Author

golddranks commented Mar 1, 2017

Okay, I did some testing.

I git cloned the Rust source, edited away the crate-type = ["dylib"] annotation in libproc_macro, librustc_data_structures, librustc_errors, libsyntax and libsyntax_pos. (Transitive deps of libproc_macro)

After that, I built a rlib of libproc_macro with cargo build --target=x86_64-unknown-linux-musl. (This is on the newest nightly.)

After that, I copied the build artefacts from ~/rust/src/target/x86_64-unknown-linux-musl/debug/deps/ to ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib.

After that, I try to compile the things that failed before with musl target → it works.

So, it seems that there isn't any real technical hurdles. (or if there is, I haven't encountered them yet)

@alexcrichton, what do you think of distributing rlibs of aforementioned libraries with the musl target?

@golddranks
Copy link
Contributor Author

Btw. I did this work on a Linux host. Tried to do the same on macOS (with musl target of course), but on macOS the linking fails with ld: unknown option: --as-needed. The linker is passed a flag --as-needed which seems to be supported on GNU linker only.

@golddranks
Copy link
Contributor Author

Ah, okay, the --as-needed behaviour is explained here: #34282

@alexcrichton
Copy link
Member

Yes there are technical hurdles in terms of build system of doing that. This is also rarely what you want because there's no reason to have a full Rust parser linked into a binary (when it's not used).

@golddranks
Copy link
Contributor Author

I see, that's a convincing argument.

@drozdziak1
Copy link

Hello,
sorry to dig up a closed issue, but I'm experiencing the same problem during an OpenWrt cross build (i686-unknown-linux-musl is the Rust target and VirtualBox is the OpenWrt one). My compiler is rustc 1.25.0-nightly (61452e506 2018-01-09). I've got a couple questions regarding this:

  • Is the root cause known? What is it?
  • Is there a solution out there?
  • If not, where can I go to help solve this?

malbarbo added a commit to malbarbo/tectonic that referenced this issue Nov 15, 2018
Musl target does not work with proc-macro.
See rust-lang/rust#40174

Removing serde-derive allows building tectonic for musl targets.
@lisbakke
Copy link

Hello! I've got this issue, as well -- deps relying on proc-macro2 which do not use default-features = false so proc-macro crate is not found because my target does not have it.

I'm currently compiling rustc for my target and it seems easiest to create proc-macro lib when I'm building. Is there any documentation on how to do this?

@mmastrac
Copy link

mmastrac commented Oct 6, 2019

For those following various links to this issue, it is important to note that you can compile code using proc_macro to statically-linked musl binaries, BUT you need to cross-compile from a platform that does support dynamic linking.

cargo build --target x86_64-unknown-linux-musl should be sufficient, but you'll need to run that on something like Ubuntu, Fedora, or another full system.

@jonas-schievink
Copy link
Contributor

Reopening as this seems to still be a significant issue for people building from musl systems

@jonas-schievink jonas-schievink added A-linkage Area: linking into static, shared libraries and binaries A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. O-musl Target: The musl libc labels Nov 17, 2019
@masonk
Copy link

masonk commented Dec 30, 2019

--target x86_64-unknown-linux-musl doesn't work for me and shouldn't be considered a sufficient workaround.

Many important crates like OpenSSL need to be vendored and cross-compiled to musl (e.g., sfackler/rust-openssl#980 (comment)), but when I tried to do that, complications like feature flags not working with workspaces (e.g, rust-lang/cargo#5015) started cropping up, and I threw up my hands and gave up on musl.

Even if there aren't plans to work on it in the near term, I don't think this issue should be considered fixed until either (1) It is easy to cross-compile apps to musl or (2) it is possible to cis-compile proc_macro targets on musl.

@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 30, 2019
frebib added a commit to frebib/kipa that referenced this issue Jan 14, 2020
Use starlark to de-duplicate most of the configuration.

Use rust:buster-slim base as there is a problem with rust on alpine
currently: rust-lang/rust#40174

Signed-off-by: Joe Groocock <[email protected]>
@Ekleog
Copy link

Ekleog commented Apr 16, 2020

There are likely much better solutions, but… I've just come across https://github.com/dtolnay/watt ; and… would integrating this into rustc as a secondary backend for use only on platforms where regular proc macros aren't supported be a solution? It wouldn't support all the use cases I think, due to regular proc macros being allowed to eg. interact with the FS, but it should already support a number of use cases. And maybe, with time, the API could be extended so that proc macros could all be compiled with wasm, and the current dylib approach could be dropped, thus making porting rustc to a new architecture a lot easier?

@mati865
Copy link
Contributor

mati865 commented Apr 16, 2020

@Ekleog is it still an issue after #69519?

@Ekleog
Copy link

Ekleog commented Apr 16, 2020

@mati865 I'm not sure, I've pinged here following a message from IRC that said this happened just today -- don't know for sure the version of the compiler used, so I've just pinged them

@breard-r
Copy link

@mati865 If it's part of the brand new Rust 1.43, then yes, it is still an issue.

On Alpine, the heavily patched rust package (1.39) can compile without any trouble. However, on the very same machine, any version of Rust (including 1.39 and 1.43) installed via rustup (and therefore without those patches) is subject to this issue.

@12101111
Copy link
Contributor

@breard-r Rust 1.43 don't include this patch and you can try 1.44 beta from rustup.

@breard-r
Copy link

@12101111 Thank you! I've just installed 1.44.0-beta via rustup and it builds! 😃

@jonas-schievink
Copy link
Contributor

Great! Closing as fixed then.

@jyn514
Copy link
Member

jyn514 commented May 23, 2020

This is still broken for me using rustc 1.44.0-beta.3 (0f0d70055 2020-05-11).

  = note: /usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find crti.o: No such file or directory
Full linker arguments
/rcc # cargo build
   Compiling thiserror-impl v1.0.19
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-m64" "-L" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.0.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.1.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.10.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.11.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.12.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.13.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.14.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.15.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.2.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.3.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.4.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.5.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.6.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.7.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.8.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.9.rcgu.o" "-o" "/rcc/target/debug/deps/libthiserror_impl-c05c536330366b8e.so" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.1x6px3h632f37ynj.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.2thl14zymh2c935g.rcgu.o" "-Wl,--gc-sections" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/rcc/target/debug/deps" "-L" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Wl,-Bstatic" "/rcc/target/debug/deps/libsyn-fe2290862b758c2c.rlib" "/rcc/target/debug/deps/libquote-afe91c35027afeba.rlib" "/rcc/target/debug/deps/libproc_macro2-0913bab1357133a2.rlib" "/rcc/target/debug/deps/libunicode_xid-8b9fbfbf3102211f.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libproc_macro-84e8be3f2684e30a.rlib" "-Wl,--start-group" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-5ee1781929f9655d.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-e2ec5d2aca499f1c.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libhashbrown-81740b8a57dba39b.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_alloc-eb99f2d2958ad0d9.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libbacktrace-84349410b417ab27.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libbacktrace_sys-b3c09d3262227e0b.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_demangle-c58a107a6842bb60.rlib" "/tmp/rustc3EmKiY/libunwind-33abd88ac2c901d5.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcfg_if-c210a18d812061d6.rlib" "/tmp/rustc3EmKiY/liblibc-2b136be5748c5959.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-150a1e69c064728f.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_core-e390c28232836237.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-1cdf993f577c22fa.rlib" "-Wl,--end-group" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-9211daa04cc43fa3.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lc" "-shared"
  = note: /usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find crti.o: No such file or directory
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

error: could not compile `thiserror-impl`.

@12101111
Copy link
Contributor

This is still broken for me using rustc 1.44.0-beta.3 (0f0d70055 2020-05-11).

  = note: /usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find crti.o: No such file or directory

Full linker arguments

/rcc # cargo build
   Compiling thiserror-impl v1.0.19
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-m64" "-L" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.0.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.1.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.10.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.11.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.12.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.13.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.14.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.15.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.2.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.3.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.4.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.5.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.6.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.7.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.8.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.thiserror_impl.7sf2w6hc-cgu.9.rcgu.o" "-o" "/rcc/target/debug/deps/libthiserror_impl-c05c536330366b8e.so" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.1x6px3h632f37ynj.rcgu.o" "/rcc/target/debug/deps/thiserror_impl-c05c536330366b8e.2thl14zymh2c935g.rcgu.o" "-Wl,--gc-sections" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/rcc/target/debug/deps" "-L" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Wl,-Bstatic" "/rcc/target/debug/deps/libsyn-fe2290862b758c2c.rlib" "/rcc/target/debug/deps/libquote-afe91c35027afeba.rlib" "/rcc/target/debug/deps/libproc_macro2-0913bab1357133a2.rlib" "/rcc/target/debug/deps/libunicode_xid-8b9fbfbf3102211f.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libproc_macro-84e8be3f2684e30a.rlib" "-Wl,--start-group" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-5ee1781929f9655d.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-e2ec5d2aca499f1c.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libhashbrown-81740b8a57dba39b.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_alloc-eb99f2d2958ad0d9.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libbacktrace-84349410b417ab27.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libbacktrace_sys-b3c09d3262227e0b.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_demangle-c58a107a6842bb60.rlib" "/tmp/rustc3EmKiY/libunwind-33abd88ac2c901d5.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcfg_if-c210a18d812061d6.rlib" "/tmp/rustc3EmKiY/liblibc-2b136be5748c5959.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-150a1e69c064728f.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_core-e390c28232836237.rlib" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-1cdf993f577c22fa.rlib" "-Wl,--end-group" "/usr/local/rustup/toolchains/beta-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-9211daa04cc43fa3.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lc" "-shared"
  = note: /usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find crti.o: No such file or directory
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

error: could not compile `thiserror-impl`.

It seems you don't install musl-dev

@jyn514
Copy link
Member

jyn514 commented May 23, 2020

That fixed it, thank you!

raatiniemi added a commit to raatiniemi/linker that referenced this issue May 22, 2021
either the opentelemetry or rayon requires that the `musl-dev` package
is installed while building otherwise the build will fail with the
following error message:

`.../bin/ld: cannot find crti.o: No such file or directory`

ref: rust-lang/rust#40174 (comment)
@WhyNotHugo
Copy link

If you're bumping into this in 2021, it's likely that you need to run apk add --no-cache musl-dev.

perennialtech added a commit to perennialtech/inv_sig_helper that referenced this issue Aug 14, 2024
…command"

This reverts commit ff9a378.

Reasons for reverting:
1. Compiling via musl is necessary to statically link dependencies and create a truly standalone Rust binary. [1]
2. Alpine-based Rust images are required for the build stage because such systems support dynamic linking, which is also needed for statically-linked binaries. [2]
3. Determining the target architecture and templating the correct value for the --target flag is necessary for the statically-linked binary to be built correctly. [2]

[1]: https://doc.rust-lang.org/1.13.0/book/advanced-linking.html#linux
[2]: rust-lang/rust#40174 (comment)
unixfox pushed a commit to iv-org/inv_sig_helper that referenced this issue Aug 14, 2024
* add compose.yaml

* add Dockerfile

* update README

* Dockerfile: uncomment CMD instruction

* add .dockerignore

* Dockerfile: use scratch image for second stage

* Dockerfile: use newer OpenSSL version (3.0.9)

* Dockerfile: use Alpine-based Rust image to skip building OpenSSL

* Dockerfile: expose to localhost only by default

* Dockerfile: allow building for different architectures (AMD64 and ARM64)

Dockerfile now detects the architecture being used during the build process and templates in the correct Rust target architecture

* compose.yaml: include command line

* compose.yaml: listen on 127.0.0.1 only

* compose.yaml: remove healthcheck due to using scratch image

* README.md: restore old table format

* rename compose.yaml to docker-compose.yml

* docker-compose.yml: include version line

* update .dockerignore

* README.md: update Docker instructions to expose only on localhost

* add workflow to build and push container images to quay.io

* docker-compose.yml: harden configuration

* docker workflow: add paths-ignore section

* Dockerfile: let Rustup handle architecture detection

More flexible as the build process will now automatically adapt to whatever architecture the container is being built on, without needing to explicitly list out each supported architecture

* Docker: further security hardening

- Run as a non-privileged user within the scratch container
- Add security_opt: - no-new-privileges:true to docker-compose.yml

* Dockerfile: Switch to Debian-based images and simplify build command

- rust:1.80-alpine replaced with rust:1.80 for the builder stage
- alpine:3.20 replaced with debian:12.6-slim for the user-stage
- Build command simplified to use default target architecture

* Cargo.toml: correct note on optimisations

* docker-compose.yml: use quay.io image by default

* rename docker-compose.yml to docker-compose.yaml

* compose: build image from local repo by default

* Revert "Dockerfile: Switch to Debian-based images and simplify build command"

This reverts commit ff9a378.

Reasons for reverting:
1. Compiling via musl is necessary to statically link dependencies and create a truly standalone Rust binary. [1]
2. Alpine-based Rust images are required for the build stage because such systems support dynamic linking, which is also needed for statically-linked binaries. [2]
3. Determining the target architecture and templating the correct value for the --target flag is necessary for the statically-linked binary to be built correctly. [2]

[1]: https://doc.rust-lang.org/1.13.0/book/advanced-linking.html#linux
[2]: rust-lang/rust#40174 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. O-musl Target: The musl libc T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests