{"record":{"id":"5fb54636f8ffc991","repo":"microsoft/aspire","slug":"the-rust-app-resource-name-targets-target-but-the-default","errorCode":null,"errorMessage":"The Rust app '{resource.Name}' targets '{target}', but the default Rust build image does not support container target platform '{platform}'. Configure buildImage with WithDockerfileBaseImage before publishing.","messagePattern":"The Rust app '(.+?)' targets '(.+?)', but the default Rust build image does not support container target platform '(.+?)'\\. Configure buildImage with WithDockerfileBaseImage before publishing\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Rust/RustHostingExtensions.cs","lineNumber":914,"sourceCode":"\n        var baseImages = container.Annotations.OfType<DockerfileBaseImageAnnotation>().LastOrDefault()\n            ?? resource.Annotations.OfType<DockerfileBaseImageAnnotation>().LastOrDefault();\n        var customBuildImageConfigured = baseImages?.BuildImage is not null;\n        var customRuntimeImageConfigured = baseImages?.RuntimeImage is not null;\n\n        if (!defaultBuildImageCompatible && !defaultRuntimeImageCompatible\n            && (!customBuildImageConfigured || !customRuntimeImageConfigured))\n        {\n            throw new DistributedApplicationException(\n                $\"The Rust app '{resource.Name}' targets '{target}', which is not compatible with the default \" +\n                \"musl build and runtime images. Configure both images in a single \" +\n                \"WithDockerfileBaseImage(buildImage: ..., runtimeImage: ...) call before publishing; later calls replace \" +\n                \"the previous configuration.\");\n        }\n\n        if (!defaultBuildImageCompatible && !customBuildImageConfigured)\n        {\n            throw new DistributedApplicationException(\n                $\"The Rust app '{resource.Name}' targets '{target}', but the default Rust build image does not support \" +\n                $\"container target platform '{platform}'. Configure buildImage with WithDockerfileBaseImage before publishing.\");\n        }\n\n        if (!defaultRuntimeImageCompatible && !customRuntimeImageConfigured)\n        {\n            throw new DistributedApplicationException(\n                $\"The Rust app '{resource.Name}' targets '{target}', but the default Rust runtime image is not compatible \" +\n                \"with its target ABI. Configure runtimeImage with WithDockerfileBaseImage before publishing.\");\n        }\n\n        return platform;\n    }\n\n    private static DistributedApplicationException CreateUnsupportedContainerTargetException(\n        RustAppResource resource,\n        string target)\n        => new(","sourceCodeStart":896,"sourceCodeEnd":932,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Rust/RustHostingExtensions.cs#L896-L932","documentation":"Aspire's Rust integration generates a Dockerfile at publish time. When a cargo target is specified (via WithCargoOptions target), the integration maps the target's architecture to a container platform and checks whether the default Rust build image (official Rust image, musl-based) supports that platform. The default build image only publishes amd64 and arm64 variants, so for other platforms (linux/arm, linux/386) the library throws at publish time unless you supply a custom build image with WithDockerfileBaseImage.","triggerScenarios":"Calling builder.AddRustApp(...).WithCargoOptions(o => o.WithTarget(\"armv7-unknown-linux-musleabihf\")) (or any i386/i486/i586/i686/arm/armv4t/armv5te/armv7/thumbv7neon target) and then publishing (app host publish mode), without having called WithDockerfileBaseImage with a non-null buildImage. ResolveContainerTargetPlatform (called from FinalizePublishDockerfile) computes defaultBuildImageCompatible=false (platform not LinuxAmd64/LinuxArm64, or environment not musl) and customBuildImageConfigured=false.","commonSituations":"Cross-compiling a Rust app for 32-bit ARM devices (Raspberry Pi) or 32-bit x86 targets using the default images; upgrading the Aspire Rust integration when adding a non-amd64/arm64 target; forgetting WithDockerfileBaseImage when switching from a host-arch target to an embedded/ARM target.","solutions":["Configure a custom build image that supports the target platform: call WithDockerfileBaseImage(buildImage: \"<image supporting your target>\") on the Rust resource before publishing.","If both build and runtime images are incompatible, configure both in a single WithDockerfileBaseImage(buildImage: ..., runtimeImage: ...) call — later calls replace the previous configuration entirely.","If you don't actually need that cargo target (e.g. you are building for the host arch), remove or change the WithCargoOptions target to x86_64-unknown-linux-musl or aarch64-unknown-linux-musl so the default image works.","For targets the platform mapper cannot handle (custom target JSON, non-Linux targets), author your own Dockerfile instead of relying on the generated one."],"exampleFix":"// before\nbuilder.AddRustApp(\"api\", \"../api\")\n    .WithCargoOptions(o => o.WithTarget(\"armv7-unknown-linux-musleabihf\"));\n\n// after\nbuilder.AddRustApp(\"api\", \"../api\")\n    .WithCargoOptions(o => o.WithTarget(\"armv7-unknown-linux-musleabihf\"))\n    .WithDockerfileBaseImage(\n        buildImage: \"rust:1-bookworm\",       // multi-arch builder supporting armv7 cross builds\n        runtimeImage: \"debian:bookworm-slim\");","handlingStrategy":"validation","validationCode":"// Before publishing, verify the cargo target maps to a default-supported platform\nvar target = \"armv7-unknown-linux-musleabihf\"; // your WithCargoOptions target\nvar parts = target.Split('-');\nvar arch = parts[0];\nvar supported = arch is \"x86_64\" or \"aarch64\" && parts[^1] == \"musl\";\nif (!supported)\n{\n    // configure WithDockerfileBaseImage(buildImage: ...) before publishing\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    // app host publish/run\n}\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"default Rust build image\"))\n{\n    // surface guidance: configure WithDockerfileBaseImage(buildImage: ...) for this target\n}","preventionTips":["Only rely on the generated Dockerfile for x86_64-unknown-linux-musl or aarch64-unknown-linux-musl targets.","Pair every non-standard cargo target with a WithDockerfileBaseImage call in the same builder chain.","Test publish mode (not just run mode) whenever you add or change a cargo target triple.","Configure build and runtime images in a single WithDockerfileBaseImage call — later calls replace the previous configuration."],"tags":["rust","docker","publishing","cross-compilation","containers"],"backgroundTag":"unsupported-platform","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}