diff --git a/python/mozbuild/mozbuild/backend/recursivemake.py b/python/mozbuild/mozbuild/backend/recursivemake.py index 858d4d40cefb..f9f788f55c3d 100644 --- a/python/mozbuild/mozbuild/backend/recursivemake.py +++ b/python/mozbuild/mozbuild/backend/recursivemake.py @@ -1201,8 +1201,9 @@ class RecursiveMakeBackend(MakeBackend): self, obj, backend_file, target_variable, target_cargo_variable ): backend_file.write_once("CARGO_FILE := %s\n" % obj.cargo_file) - backend_file.write_once("CARGO_TARGET_DIR := .\n") - backend_file.write("%s += %s\n" % (target_variable, obj.location)) + target_dir = mozpath.normpath(backend_file.environment.topobjdir) + backend_file.write("CARGO_TARGET_DIR := %s\n" % target_dir) + backend_file.write("%s += $(DEPTH)/%s\n" % (target_variable, obj.location)) backend_file.write("%s += %s\n" % (target_cargo_variable, obj.name)) def _process_rust_program(self, obj, backend_file): diff --git a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py index 9ddb02bd2d31..d53063b30560 100644 --- a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py +++ b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py @@ -1011,10 +1011,11 @@ class TestRecursiveMakeBackend(BackendTester): expected = [ "CARGO_FILE := %s/code/Cargo.toml" % env.topsrcdir, - "CARGO_TARGET_DIR := .", - "RUST_PROGRAMS += i686-pc-windows-msvc/release/target.exe", + "CARGO_TARGET_DIR := %s" % env.topobjdir, + "RUST_PROGRAMS += $(DEPTH)/i686-pc-windows-msvc/release/target.exe", "RUST_CARGO_PROGRAMS += target", - "HOST_RUST_PROGRAMS += i686-pc-windows-msvc/release/host.exe", + "CARGO_TARGET_DIR := %s" % env.topobjdir, + "HOST_RUST_PROGRAMS += $(DEPTH)/i686-pc-windows-msvc/release/host.exe", "HOST_RUST_CARGO_PROGRAMS += host", ]