From dcbd9f905c3ea9b221eb94fe6c838c375a71ca4b Mon Sep 17 00:00:00 2001 From: occheung Date: Wed, 1 Sep 2021 17:45:27 +0800 Subject: [PATCH] cargo: use cargo xbuild --- artiq/firmware/bootloader/Makefile | 6 +++++- artiq/firmware/ksupport/Makefile | 6 +++++- artiq/firmware/runtime/Makefile | 6 +++++- artiq/firmware/satman/Makefile | 4 +++- flake.nix | 15 +++++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/artiq/firmware/bootloader/Makefile b/artiq/firmware/bootloader/Makefile index 482aa3291..4dbd7b608 100644 --- a/artiq/firmware/bootloader/Makefile +++ b/artiq/firmware/bootloader/Makefile @@ -3,11 +3,15 @@ include $(MISOC_DIRECTORY)/software/common.mak RUSTFLAGS += -Cpanic=abort +export XBUILD_SYSROOT_PATH=$(BUILDINC_DIRECTORY)/../sysroot + all:: bootloader.bin .PHONY: $(RUSTOUT)/libbootloader.a $(RUSTOUT)/libbootloader.a: - $(cargo) --manifest-path $(BOOTLOADER_DIRECTORY)/Cargo.toml + $(cargo) --target-dir ./cargo \ + --manifest-path $(BOOTLOADER_DIRECTORY)/Cargo.toml \ + --target $(BOOTLOADER_DIRECTORY)/../riscv32ima-unknown-none-elf.json bootloader.elf: $(RUSTOUT)/libbootloader.a $(link) -T $(BOOTLOADER_DIRECTORY)/bootloader.ld diff --git a/artiq/firmware/ksupport/Makefile b/artiq/firmware/ksupport/Makefile index cfb79b3d6..f1fbfc19a 100644 --- a/artiq/firmware/ksupport/Makefile +++ b/artiq/firmware/ksupport/Makefile @@ -14,11 +14,15 @@ LDFLAGS += --eh-frame-hdr \ RUSTFLAGS += -Cpanic=unwind +export XBUILD_SYSROOT_PATH=$(BUILDINC_DIRECTORY)/../sysroot + all:: ksupport.elf .PHONY: $(RUSTOUT)/libksupport.a $(RUSTOUT)/libksupport.a: - $(cargo) --manifest-path $(KSUPPORT_DIRECTORY)/Cargo.toml + $(cargo) --target-dir ./cargo \ + --manifest-path $(KSUPPORT_DIRECTORY)/Cargo.toml \ + --target $(KSUPPORT_DIRECTORY)/../riscv32ima-unknown-none-elf.json ksupport.elf: $(RUSTOUT)/libksupport.a glue.o $(link) -T $(KSUPPORT_DIRECTORY)/ksupport.ld \ diff --git a/artiq/firmware/runtime/Makefile b/artiq/firmware/runtime/Makefile index 24ac19741..00506b2f3 100644 --- a/artiq/firmware/runtime/Makefile +++ b/artiq/firmware/runtime/Makefile @@ -10,11 +10,15 @@ LDFLAGS += \ RUSTFLAGS += -Cpanic=unwind +export XBUILD_SYSROOT_PATH=$(BUILDINC_DIRECTORY)/../sysroot + all:: runtime.bin runtime.fbi .PHONY: $(RUSTOUT)/libruntime.a $(RUSTOUT)/libruntime.a: - $(cargo) --manifest-path $(RUNTIME_DIRECTORY)/Cargo.toml + $(cargo) --target-dir ./cargo \ + --manifest-path $(RUNTIME_DIRECTORY)/Cargo.toml \ + --target $(RUNTIME_DIRECTORY)/../riscv32ima-unknown-none-elf.json runtime.elf: $(RUSTOUT)/libruntime.a ksupport_data.o $(link) -T $(RUNTIME_DIRECTORY)/runtime.ld \ diff --git a/artiq/firmware/satman/Makefile b/artiq/firmware/satman/Makefile index 59f0f78f6..1f441c018 100644 --- a/artiq/firmware/satman/Makefile +++ b/artiq/firmware/satman/Makefile @@ -9,7 +9,9 @@ all:: satman.bin satman.fbi .PHONY: $(RUSTOUT)/libsatman.a $(RUSTOUT)/libsatman.a: - $(cargo) --manifest-path $(SATMAN_DIRECTORY)/Cargo.toml + $(cargo) --target-dir ./cargo \ + --manifest-path $(SATMAN_DIRECTORY)/Cargo.toml \ + --target $(SATMAN_DIRECTORY)/../riscv32ima-unknown-none-elf.json satman.elf: $(RUSTOUT)/libsatman.a $(link) -T $(SATMAN_DIRECTORY)/satman.ld diff --git a/flake.nix b/flake.nix index dc192e57b..3ad177a03 100644 --- a/flake.nix +++ b/flake.nix @@ -180,6 +180,20 @@ propagatedBuildInputs = with pkgs.python3Packages; [ jinja2 numpy migen pyserial asyncserial ]; }; + cargo-xbuild = rustPlatform.buildRustPackage rec { + pname = "cargo-xbuild"; + version = "0.6.5"; + + src = pkgs.fetchFromGitHub { + owner = "rust-osdev"; + repo = pname; + rev = "v${version}"; + sha256 = "18djvygq9v8rmfchvi2hfj0i6fhn36m716vqndqnj56fiqviwxvf"; + }; + + cargoSha256 = "13sj9j9kl6js75h9xq0yidxy63vixxm9q3f8jil6ymarml5wkhx8"; + }; + vivadoEnv = pkgs.buildFHSUserEnv { name = "vivado-env"; targetPkgs = vivadoDeps; @@ -211,6 +225,7 @@ pkgs.lld_11 vivado rustPlatform.cargoSetupHook + cargo-xbuild ]; buildPhase = ''