From c8c7654fc7a166fea7dfcc4d6c66b50d60da86ab Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Tue, 24 Apr 2018 21:34:30 -0400 Subject: [PATCH 01/14] [AVR][No Upstream] Move aside Rust README --- README.md => RUST_README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.md => RUST_README.md (100%) diff --git a/README.md b/RUST_README.md similarity index 100% rename from README.md rename to RUST_README.md From d020dd7a046dbdc66407cbea42fc72de3291234b Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Fri, 6 May 2016 09:51:21 -0400 Subject: [PATCH 02/14] [AVR][No Upstream] Add AVR-Rust README --- README.md | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000000000..327af708dc040 --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +# Rust with AVR support + +[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/avr-rust) + +This project adds support for the [AVR](https://en.wikipedia.org/wiki/Atmel_AVR) +microcontroller to Rust. + +It uses the [AVR-LLVM backend](http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AVR/). + +## Caveats + +While the stock libcore may be compiled, certain code patterns may +still exercise code in LLVM that is broken or that produces +miscompiled code. Looking for existing issues or submitting a new +issue is appreciated! + +## Building and installation + +This will compile Rust with AVR support. This will not create a +fully-fledged cross-compiler, however, as it does not compile any libraries +such as `libcore` or `liblibc`. To do this, the `--target=avr-unknown-unknown` +flag must be passed to `configure`, which is not fully supported yet due to bugs. + +First make sure you've installed all dependencies for building, as specified in +the main Rust repository [here](https://github.com/rust-lang/rust/#building-from-source). +Then use the following commands: + +``` bash +# Grab the avr-rust sources +git clone https://github.com/avr-rust/rust.git + +# Create a directory to place built files in +mkdir build && cd build + +# Generate Makefile using settings suitable for an experimental compiler +../rust/configure \ + --enable-debug \ + --disable-docs \ + --enable-llvm-assertions \ + --enable-debug-assertions \ + --enable-optimize \ + --enable-llvm-release-debuginfo \ + --experimental-targets=AVR \ + --prefix=/opt/avr-rust + +# Build the compiler, optionally install it to /opt/avr-rust +make +make install + +# Register the toolchain with rustup +rustup toolchain link avr-toolchain $(realpath $(find . -name 'stage1')) + +# Optionally enable the avr toolchain globally +rustup default avr-toolchain +``` + +## Usage + +# With Xargo (recommended) + +Take a look at the example [blink](https://github.com/avr-rust/blink) program. + +# Vanilla `rustc` + +AVR support is enabled by passing the `--target avr-unknown-unknown` flag to `rustc`. + +Note that the Rust `libcore` library (essentially required for every Rust program), +must be manually compiled for it to be used, as it will not be built for AVR during +compiler compilation (yet). Work is currently being done in order to allow `libcore` +to be automatically compiled for AVR. From a28ee4d6a1004dced6214ef0f620f37f399d5ecf Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Mon, 12 Dec 2016 09:07:49 -0500 Subject: [PATCH 03/14] [AVR][No Upstream] Move aside travis.yml --- .travis.yml => .travis_rust.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .travis.yml => .travis_rust.yml (100%) diff --git a/.travis.yml b/.travis_rust.yml similarity index 100% rename from .travis.yml rename to .travis_rust.yml From 3267ae829f20e276a507e8a056b465e67272168f Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Fri, 6 May 2016 09:55:40 -0400 Subject: [PATCH 04/14] [AVR][No Upstream] Add AVR-Rust specific travis-ci manifest --- .travis.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000000..7249af7ac0328 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,32 @@ +language: generic +sudo: required +services: + - docker + +# LLVM takes awhile to check out and otherwise we'll manage the submodules in +# our configure script, so disable auto submodule management. +git: + submodules: false + depth: 1 + +env: + - CXX=/usr/bin/g++-4.7 RUST_BACKTRACE=1 + +before_install: + - docker build -t rust -f src/etc/Dockerfile src/etc + +script: + - docker run -v `pwd`:/build rust + sh -c " + ./configure --enable-rustbuild --llvm-root=/usr/lib/llvm-3.7 --enable-quiet-tests && + make tidy && + make check -j4 + " + +# Real testing happens on http://buildbot.rust-lang.org/ +# +# See https://github.com/rust-lang/rust-buildbot +# CONTRIBUTING.md#pull-requests + +notifications: + email: false From d71ae5ed639e83ecac0445729f332920d97a22d1 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Sun, 22 Jul 2018 18:58:36 +1200 Subject: [PATCH 05/14] [AVR][No Upstream] Add Jenkinsfile --- Jenkinsfile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000000..ab3e292f1e8c5 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,14 @@ +node('master') { + stage('Checkout') { + checkout scm + sh 'git submodule update --init --recursive' + } + + stage('Build') { + dir('build') { + sh '../x.py build' + } + } +} + + From 043550d9db0582add42e5837f636f61acb26b915 Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Fri, 6 May 2016 09:32:10 -0400 Subject: [PATCH 06/14] [AVR] Add AVR platform support --- config.toml.example | 2 +- src/bootstrap/config.rs | 2 +- src/librustc/ich/impls_syntax.rs | 2 + src/librustc/ty/layout.rs | 2 + src/librustc_codegen_llvm/abi.rs | 2 + src/librustc_codegen_llvm/llvm/ffi.rs | 2 + src/librustc_llvm/build.rs | 2 +- src/librustc_llvm/lib.rs | 6 +++ src/librustc_target/abi/call/avr.rs | 43 +++++++++++++++++++ src/librustc_target/abi/call/mod.rs | 4 ++ src/librustc_target/spec/abi.rs | 5 +++ .../spec/avr_unknown_unknown.rs | 27 ++++++++++++ src/librustc_target/spec/mod.rs | 5 ++- src/librustc_target/spec/none_base.rs | 37 ++++++++++++++++ src/libstd/env.rs | 6 +++ src/libsyntax/feature_gate.rs | 8 ++++ src/libsyntax_pos/symbol.rs | 1 + src/rustllvm/PassWrapper.cpp | 7 +++ .../feature-gate-abi-avr-interrupt.rs | 19 ++++++++ .../feature-gate-abi-avr-interrupt.stderr | 11 +++++ src/tools/compiletest/src/util.rs | 2 + 21 files changed, 191 insertions(+), 4 deletions(-) create mode 100644 src/librustc_target/abi/call/avr.rs create mode 100644 src/librustc_target/spec/avr_unknown_unknown.rs create mode 100644 src/librustc_target/spec/none_base.rs create mode 100644 src/test/ui/feature-gates/feature-gate-abi-avr-interrupt.rs create mode 100644 src/test/ui/feature-gates/feature-gate-abi-avr-interrupt.stderr diff --git a/config.toml.example b/config.toml.example index c14adf8ce33c7..ac8c1955feb42 100644 --- a/config.toml.example +++ b/config.toml.example @@ -64,7 +64,7 @@ # not built by default and the experimental Rust compilation targets that depend # on them will not work unless the user opts in to building them. By default the # `WebAssembly` and `RISCV` targets are enabled when compiling LLVM from scratch. -#experimental-targets = "WebAssembly;RISCV" +#experimental-targets = "AVR;WebAssembly;RISCV" # Cap the number of parallel linker invocations when compiling LLVM. # This can be useful when building LLVM with debug info, which significantly diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 66f504ea924e9..90d309af09d7b 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -525,7 +525,7 @@ impl Config { set(&mut config.llvm_link_shared, llvm.link_shared); config.llvm_targets = llvm.targets.clone(); config.llvm_experimental_targets = llvm.experimental_targets.clone() - .unwrap_or_else(|| "WebAssembly;RISCV".to_string()); + .unwrap_or_else(|| "AVR;WebAssembly;RISCV".to_string()); config.llvm_link_jobs = llvm.link_jobs; config.llvm_version_suffix = llvm.version_suffix.clone(); config.llvm_clang_cl = llvm.clang_cl.clone(); diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index e0c01277801d4..04c8d81317cee 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -106,6 +106,8 @@ impl_stable_hash_for!(enum ::rustc_target::spec::abi::Abi { Msp430Interrupt, X86Interrupt, AmdGpuKernel, + AvrInterrupt, + AvrNonBlockingInterrupt, Rust, C, System, diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 8e2c3dd3d8ad9..e178213cabd0c 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -2389,6 +2389,8 @@ where Msp430Interrupt => Conv::Msp430Intr, X86Interrupt => Conv::X86Intr, AmdGpuKernel => Conv::AmdGpuKernel, + AvrInterrupt => Conv::AvrInterrupt, + AvrNonBlockingInterrupt => Conv::AvrNonBlockingInterrupt, // These API constants ought to be more specific... Cdecl => Conv::C, diff --git a/src/librustc_codegen_llvm/abi.rs b/src/librustc_codegen_llvm/abi.rs index 38d4b7e3f9d85..5214272ae6ae6 100644 --- a/src/librustc_codegen_llvm/abi.rs +++ b/src/librustc_codegen_llvm/abi.rs @@ -371,6 +371,8 @@ impl<'tcx> FnTypeLlvmExt<'tcx> for FnType<'tcx, Ty<'tcx>> { match self.conv { Conv::C => llvm::CCallConv, Conv::AmdGpuKernel => llvm::AmdGpuKernel, + Conv::AvrInterrupt => llvm::AvrInterrupt, + Conv::AvrNonBlockingInterrupt => llvm::AvrNonBlockingInterrupt, Conv::ArmAapcs => llvm::ArmAapcsCallConv, Conv::Msp430Intr => llvm::Msp430Intr, Conv::PtxKernel => llvm::PtxKernel, diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs index a71243c7c826b..e4314e3520b19 100644 --- a/src/librustc_codegen_llvm/llvm/ffi.rs +++ b/src/librustc_codegen_llvm/llvm/ffi.rs @@ -43,6 +43,8 @@ pub enum CallConv { X86_64_Win64 = 79, X86_VectorCall = 80, X86_Intr = 83, + AvrNonBlockingInterrupt = 84, + AvrInterrupt = 85, AmdGpuKernel = 91, } diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index 7fa83dd977950..dd7237948f6d0 100644 --- a/src/librustc_llvm/build.rs +++ b/src/librustc_llvm/build.rs @@ -70,7 +70,7 @@ fn main() { let is_crossed = target != host; let mut optional_components = - vec!["x86", "arm", "aarch64", "amdgpu", "mips", "powerpc", + vec!["x86", "arm", "aarch64", "amdgpu", "avr", "mips", "powerpc", "systemz", "jsbackend", "webassembly", "msp430", "sparc", "nvptx"]; let mut version_cmd = Command::new(&llvm_config); diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 292ce8b0a01b0..4b26bca109363 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -41,6 +41,12 @@ pub fn initialize_available_targets() { LLVMInitializeARMTargetMC, LLVMInitializeARMAsmPrinter, LLVMInitializeARMAsmParser); + init_target!(llvm_component = "avr", + LLVMInitializeAVRTargetInfo, + LLVMInitializeAVRTarget, + LLVMInitializeAVRTargetMC, + LLVMInitializeAVRAsmPrinter, + LLVMInitializeAVRAsmParser); init_target!(llvm_component = "aarch64", LLVMInitializeAArch64TargetInfo, LLVMInitializeAArch64Target, diff --git a/src/librustc_target/abi/call/avr.rs b/src/librustc_target/abi/call/avr.rs new file mode 100644 index 0000000000000..060834e12222b --- /dev/null +++ b/src/librustc_target/abi/call/avr.rs @@ -0,0 +1,43 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(non_upper_case_globals)] + +use crate::abi::call::{FnType, ArgType}; + +fn classify_ret_ty(ret: &mut ArgType<'_, Ty>) { + if ret.layout.is_aggregate() { + ret.make_indirect(); + } else { + ret.extend_integer_width_to(8); // Is 8 correct? + } +} + +fn classify_arg_ty(arg: &mut ArgType<'_, Ty>) { + if arg.layout.is_aggregate() { + arg.make_indirect(); + } else { + arg.extend_integer_width_to(8); + } +} + +pub fn compute_abi_info(fty: &mut FnType<'_, Ty>) { + if !fty.ret.is_ignore() { + classify_ret_ty(&mut fty.ret); + } + + for arg in &mut fty.args { + if arg.is_ignore() { + continue; + } + + classify_arg_ty(arg); + } +} diff --git a/src/librustc_target/abi/call/mod.rs b/src/librustc_target/abi/call/mod.rs index fbbd120f934be..84101d526923a 100644 --- a/src/librustc_target/abi/call/mod.rs +++ b/src/librustc_target/abi/call/mod.rs @@ -6,6 +6,7 @@ mod aarch64; mod amdgpu; mod arm; mod asmjs; +mod avr; mod hexagon; mod mips; mod mips64; @@ -516,6 +517,8 @@ pub enum Conv { X86_64Win64, AmdGpuKernel, + AvrInterrupt, + AvrNonBlockingInterrupt, } /// Metadata describing how the arguments to a native function @@ -573,6 +576,7 @@ impl<'a, Ty> FnType<'a, Ty> { wasm32::compute_abi_info(self) } } + "avr" => avr::compute_abi_info(self), "msp430" => msp430::compute_abi_info(self), "sparc" => sparc::compute_abi_info(cx, self), "sparc64" => sparc64::compute_abi_info(cx, self), diff --git a/src/librustc_target/spec/abi.rs b/src/librustc_target/spec/abi.rs index c9c41f1092240..96e6ff67d7e02 100644 --- a/src/librustc_target/spec/abi.rs +++ b/src/librustc_target/spec/abi.rs @@ -18,6 +18,8 @@ pub enum Abi { Msp430Interrupt, X86Interrupt, AmdGpuKernel, + AvrInterrupt, + AvrNonBlockingInterrupt, // Multiplatform / generic ABIs Rust, @@ -55,6 +57,9 @@ const AbiDatas: &[AbiData] = &[ AbiData {abi: Abi::Msp430Interrupt, name: "msp430-interrupt", generic: false }, AbiData {abi: Abi::X86Interrupt, name: "x86-interrupt", generic: false }, AbiData {abi: Abi::AmdGpuKernel, name: "amdgpu-kernel", generic: false }, + AbiData {abi: Abi::AvrInterrupt, name: "avr-interrupt", generic: false }, + AbiData {abi: Abi::AvrNonBlockingInterrupt, name: "avr-non-blocking-interrupt", + generic: false }, // Cross-platform ABIs AbiData {abi: Abi::Rust, name: "Rust", generic: true }, diff --git a/src/librustc_target/spec/avr_unknown_unknown.rs b/src/librustc_target/spec/avr_unknown_unknown.rs new file mode 100644 index 0000000000000..4b6fe30b9e53a --- /dev/null +++ b/src/librustc_target/spec/avr_unknown_unknown.rs @@ -0,0 +1,27 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use crate::spec::{LinkerFlavor, Target, TargetResult}; + +pub fn target() -> TargetResult { + Ok(Target { + llvm_target: "avr-unknown-unknown".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "16".to_string(), + data_layout: "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8".to_string(), + arch: "avr".to_string(), + linker_flavor: LinkerFlavor::Gcc, + target_os: "unknown".to_string(), + target_env: "".to_string(), + target_vendor: "unknown".to_string(), + target_c_int_width: 16.to_string(), + options: super::none_base::opts(), + }) +} diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 844edbb946a51..8d2ce58fddf3c 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -54,6 +54,7 @@ mod haiku_base; mod hermit_base; mod linux_base; mod linux_musl_base; +mod none_base; mod openbsd_base; mod netbsd_base; mod solaris_base; @@ -411,6 +412,8 @@ supported_targets! { ("aarch64-fuchsia", aarch64_fuchsia), ("x86_64-fuchsia", x86_64_fuchsia), + ("avr-unknown-unknown", avr_unknown_unknown), + ("x86_64-unknown-l4re-uclibc", x86_64_unknown_l4re_uclibc), ("x86_64-unknown-redox", x86_64_unknown_redox), @@ -496,7 +499,7 @@ pub struct Target { /// Vendor name to use for conditional compilation. pub target_vendor: String, /// Architecture to use for ABI considerations. Valid options: "x86", - /// "x86_64", "arm", "aarch64", "mips", "powerpc", and "powerpc64". + /// "x86_64", "arm", "aarch64", "avr", "mips", "powerpc", and "powerpc64". pub arch: String, /// [Data layout](http://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM. pub data_layout: String, diff --git a/src/librustc_target/spec/none_base.rs b/src/librustc_target/spec/none_base.rs new file mode 100644 index 0000000000000..3ffc4d7b271f0 --- /dev/null +++ b/src/librustc_target/spec/none_base.rs @@ -0,0 +1,37 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::default::Default; +use crate::spec::{LinkerFlavor, LinkArgs, TargetOptions}; + +pub fn opts() -> TargetOptions { + let mut args = LinkArgs::new(); + + args.insert(LinkerFlavor::Gcc, vec![ + // We want to be able to strip as much executable code as possible + // from the linker command line, and this flag indicates to the + // linker that it can avoid linking in dynamic libraries that don't + // actually satisfy any symbols up to that point (as with many other + // resolutions the linker does). This option only applies to all + // following libraries so we're sure to pass it as one of the first + // arguments. + "-Wl,--as-needed".to_string(), + ]); + + TargetOptions { + dynamic_linking: false, + executables: true, + linker_is_gnu: true, + has_rpath: false, + pre_link_args: args, + position_independent_executables: true, + .. Default::default() + } +} diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 00e840a53e9c0..a5247c8de18c4 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -819,6 +819,7 @@ pub mod consts { /// - x86_64 /// - arm /// - aarch64 + /// - avr /// - mips /// - mips64 /// - powerpc @@ -930,6 +931,11 @@ mod arch { pub const ARCH: &str = "aarch64"; } +#[cfg(target_arch = "avr")] +mod arch { + pub const ARCH: &'static str = "avr"; +} + #[cfg(target_arch = "mips")] mod arch { pub const ARCH: &str = "mips"; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index b41b91c7631f5..ef9979b18e909 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -401,6 +401,9 @@ declare_features! ( // Allows `extern "x86-interrupt" fn()`. (active, abi_x86_interrupt, "1.17.0", Some(40180), None), + // `extern "avr-interrupt" fn()` + (active, abi_avr_interrupt, "1.18.0", Some(000), None), + // Allows module-level inline assembly by way of `global_asm!()`. (active, global_asm, "1.18.0", Some(35119), None), @@ -1838,6 +1841,11 @@ impl<'a> PostExpansionVisitor<'a> { Abi::X86Interrupt => { gate_feature_post!(&self, abi_x86_interrupt, span, "x86-interrupt ABI is experimental and subject to change"); + } + Abi::AvrInterrupt | Abi::AvrNonBlockingInterrupt => { + gate_feature_post!(&self, abi_avr_interrupt, span, + "avr-interrupt and avr-non-blocking-interrupt ABIs are \ + experimental and subject to change"); }, Abi::AmdGpuKernel => { gate_feature_post!(&self, abi_amdgpu_kernel, span, diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 49123e4cc30c2..cacb76887be54 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -116,6 +116,7 @@ symbols! { abi_unadjusted, abi_vectorcall, abi_x86_interrupt, + abi_avr_interrupt, aborts, advanced_slice_patterns, adx_target_feature, diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index 0ebef82d37680..03de617cf7075 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -117,6 +117,12 @@ void LLVMRustPassManagerBuilderPopulateThinLTOPassManager( #define SUBTARGET_AARCH64 #endif +#ifdef LLVM_COMPONENT_AVR +#define SUBTARGET_AVR SUBTARGET(AVR) +#else +#define SUBTARGET_AVR +#endif + #ifdef LLVM_COMPONENT_MIPS #define SUBTARGET_MIPS SUBTARGET(Mips) #else @@ -163,6 +169,7 @@ void LLVMRustPassManagerBuilderPopulateThinLTOPassManager( SUBTARGET_X86 \ SUBTARGET_ARM \ SUBTARGET_AARCH64 \ + SUBTARGET_AVR \ SUBTARGET_MIPS \ SUBTARGET_PPC \ SUBTARGET_SYSTEMZ \ diff --git a/src/test/ui/feature-gates/feature-gate-abi-avr-interrupt.rs b/src/test/ui/feature-gates/feature-gate-abi-avr-interrupt.rs new file mode 100644 index 0000000000000..806bff25e7dd8 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-abi-avr-interrupt.rs @@ -0,0 +1,19 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that the AVR interrupt ABI cannot be used when avr_interrupt +// feature gate is not used. + +extern "avr-interrupt" fn foo() {} +//~^ ERROR avr-interrupt and avr-non-blocking-interrupt ABIs are experimental and subject to change + +fn main() { + foo(); +} diff --git a/src/test/ui/feature-gates/feature-gate-abi-avr-interrupt.stderr b/src/test/ui/feature-gates/feature-gate-abi-avr-interrupt.stderr new file mode 100644 index 0000000000000..023b6121784f7 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-abi-avr-interrupt.stderr @@ -0,0 +1,11 @@ +error[E0658]: avr-interrupt and avr-non-blocking-interrupt ABIs are experimental and subject to change + --> $DIR/feature-gate-abi-avr-interrupt.rs:14:1 + | +LL | extern "avr-interrupt" fn foo() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(abi_avr_interrupt)] to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs index 8caf5ca00f505..d7e3edbd02435 100644 --- a/src/tools/compiletest/src/util.rs +++ b/src/tools/compiletest/src/util.rs @@ -24,6 +24,7 @@ const OS_TABLE: &'static [(&'static str, &'static str)] = &[ ("mingw32", "windows"), ("none", "none"), ("netbsd", "netbsd"), + ("none", "none"), ("openbsd", "openbsd"), ("redox", "redox"), ("sgx", "sgx"), @@ -42,6 +43,7 @@ const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[ ("armv7", "arm"), ("armv7s", "arm"), ("asmjs", "asmjs"), + ("avr", "avr"), ("hexagon", "hexagon"), ("i386", "x86"), ("i586", "x86"), From b48663dae6abd2f167b74bcba838f5775e0fbafd Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Tue, 22 Aug 2017 19:36:52 +1200 Subject: [PATCH 07/14] [AVR][No Upstream] Expose the 'target_cpu' feature flag --- src/librustc/session/config.rs | 5 +++++ src/librustc_target/spec/mod.rs | 6 ++++++ src/test/run-pass/cfg-target-cpu.rs | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/test/run-pass/cfg-target-cpu.rs diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 003fdd501a35a..206268c2e1971 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1492,6 +1492,7 @@ pub fn default_lib_output() -> CrateType { pub fn default_configuration(sess: &Session) -> ast::CrateConfig { let end = &sess.target.target.target_endian; let arch = &sess.target.target.arch; + let cpu = &sess.target.target.options.cpu; let wordsz = &sess.target.target.target_pointer_width; let os = &sess.target.target.target_os; let env = &sess.target.target.target_env; @@ -1521,6 +1522,10 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig { Symbol::intern("target_vendor"), Some(Symbol::intern(vendor)), )); + if sess.target.target.options.is_specific_cpu() { + ret.insert((Symbol::intern("target_cpu"), Some(Symbol::intern(cpu)))); + } + if sess.target.target.options.has_elf_tls { ret.insert((sym::target_thread_local, None)); } diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 8d2ce58fddf3c..bcd35d2009838 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -853,6 +853,12 @@ impl Default for TargetOptions { } } +impl TargetOptions { + pub fn is_specific_cpu(&self) -> bool { + self.cpu != "generic" + } +} + impl Target { /// Given a function ABI, turn it into the correct ABI for this target. pub fn adjust_abi(&self, abi: Abi) -> Abi { diff --git a/src/test/run-pass/cfg-target-cpu.rs b/src/test/run-pass/cfg-target-cpu.rs new file mode 100644 index 0000000000000..0553d2350a74d --- /dev/null +++ b/src/test/run-pass/cfg-target-cpu.rs @@ -0,0 +1,18 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub fn main() { + if cfg!(target_cpu = "cortex-a8") { + println!("Running on Cortex A8!"); + } else { + println!("Running on an arbitrary cpu"); + } +} + From a40552c17c975b4eb34ed4d7e39d9debd37b4530 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Sun, 9 Jun 2019 02:46:14 +1200 Subject: [PATCH 08/14] [AVR][No Upstream] Use forked LLVM with non-upstreamed fixes --- .gitmodules | 4 ++-- src/llvm-project | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index dd74d49828f75..a32b82666a75f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -42,8 +42,8 @@ url = https://github.com/rust-lang-nursery/edition-guide.git [submodule "src/llvm-project"] path = src/llvm-project - url = https://github.com/rust-lang/llvm-project.git - branch = rustc/8.0-2019-03-18 + url = https://github.com/avr-rust/llvm-project.git + branch = avr-rustc/8.0-2019-03-18 [submodule "src/doc/embedded-book"] path = src/doc/embedded-book url = https://github.com/rust-embedded/book.git diff --git a/src/llvm-project b/src/llvm-project index 788592fb2740d..275759724b089 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 788592fb2740d560d0614a77035b319b9d07aa38 +Subproject commit 275759724b0891ccbe080977faef5789da4b99bb From 17839c7c3c40188a94fac6a3955d7dc8f093e37c Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Sun, 9 Jun 2019 01:57:40 +1200 Subject: [PATCH 09/14] [AVR] Fix debug printing of function pointers This commit fixes debug printing of function pointers on AVR. AVR does not support `addrspacecast` instructions, and so this patch modifies libcore so that a `ptrtoint` IR instruction is used and the address space cast is avoided. --- src/libcore/ptr/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs index 80ac67d8eb57c..caef99ca47ad3 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -2631,14 +2631,14 @@ macro_rules! fnptr_impls_safety_abi { #[stable(feature = "fnptr_impls", since = "1.4.0")] impl fmt::Pointer for $FnTy { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Pointer::fmt(&(*self as *const ()), f) + fmt::Pointer::fmt(&(*self as usize as *const ()), f) } } #[stable(feature = "fnptr_impls", since = "1.4.0")] impl fmt::Debug for $FnTy { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Pointer::fmt(&(*self as *const ()), f) + fmt::Pointer::fmt(&(*self as usize as *const ()), f) } } } From 65b8041446c36eded34aa9602d0b5623842d8274 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Thu, 16 May 2019 21:38:45 +1200 Subject: [PATCH 10/14] Merge pull request #135 from ratkins/patch-1 Add extra steps for macOS, as noted in #131 --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 327af708dc040..1f1989ddb789d 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,15 @@ First make sure you've installed all dependencies for building, as specified in the main Rust repository [here](https://github.com/rust-lang/rust/#building-from-source). Then use the following commands: +### Notes for macOS + +The conventional install directory for macOS is `/usr/local/avr-rust` rather than the Linux default `/opt/avr-rust`, so before the steps below, you must: + +1. Edit `build/config.toml` to set `prefix = '/usr/local/avr-rust'`. +2. Ensure `/usr/local/avr-rust` exists and has the correct permissions: `sudo mkdir /usr/local/avr-rust && sudo chown $USER:admin /usr/local/avr-rust` + +Finally, `realpath` isn't included by default on macOS but is included in GNU Coreutils, so you can either `brew install coreutils` so the `rustup toolchain...` step works properly, or just use the explicit path (`rustup toolchain link avr-toolchain /usr/local/avr-rust`). + ``` bash # Grab the avr-rust sources git clone https://github.com/avr-rust/rust.git From 311d956cdfd6162c249455ee469430611ccc2af8 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Thu, 16 May 2019 21:44:46 +1200 Subject: [PATCH 11/14] [README] Add --recursive flag to git clone example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f1989ddb789d..6bc2d96a8d01f 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Finally, `realpath` isn't included by default on macOS but is included in GNU Co ``` bash # Grab the avr-rust sources -git clone https://github.com/avr-rust/rust.git +git clone https://github.com/avr-rust/rust.git --recursive # Create a directory to place built files in mkdir build && cd build From 9a1785d01750c81d7d5cb533c6f08d0a56749493 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Sun, 4 Nov 2018 17:21:45 +1300 Subject: [PATCH 12/14] Add Gitlab CI config and Dockerfile --- .dockerignore | 1 + .gitlab-ci.yml | 29 +++++++++++++++++++++++++++++ Dockerfile | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitlab-ci.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000..84c048a73cc2e --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +/build/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000..2ff7e7cf573b7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,29 @@ + image: docker:stable + + variables: + # When using dind service we need to instruct docker, to talk with the + # daemon started inside of the service. The daemon is available with + # a network connection instead of the default /var/run/docker.sock socket. + # + # The 'docker' hostname is the alias of the service container as described at + # https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#accessing-the-services + # + # Note that if you're using Kubernetes executor, the variable should be set to + # tcp://localhost:2375 because of how Kubernetes executor connects services + # to the job container + DOCKER_HOST: tcp://docker:2375/ + # When using dind, it's wise to use the overlayfs driver for + # improved performance. + DOCKER_DRIVER: overlay2 + + services: + - docker:dind + + before_script: + - docker info + + build: + stage: build + script: + - docker build -t avr-rust . + - docker run avr-rust echo hello world diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000..f8b3a6d28d1fa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +FROM ubuntu:18.04 + +USER root + +# Install dependencies. +RUN apt-get update && apt-get install -y build-essential cmake curl git python + +# Create a regular user. +RUN useradd -m rustacean + +# Copy the code over, create an empty directory for builds. +ADD . /code +# RUN cd /code +RUN mkdir /build && cd /build + +# symlink Rust build directory to the /build volume +# RUN mkdir /build && ln -sf /build /code/build + +# Compile rust. +# RUN /code/x.py build + +# Generate Makefile using settings suitable for an experimental compiler +RUN /code/configure \ + --enable-debug \ + --disable-docs \ + --enable-llvm-assertions \ + --enable-debug-assertions \ + --enable-optimize \ + --enable-llvm-release-debuginfo \ + --experimental-targets=AVR + +RUN make +RUN make install + +# Drop down to the regular user +USER rustacean + +VOLUME /code +VOLUME /build From 8405b30a34f2cb9feb6b0f673f1bb7829dfa6ffd Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Thu, 13 Jun 2019 10:52:43 -0400 Subject: [PATCH 13/14] Document to use stage2 Evidently there's some difference, see https://github.com/avr-rust/rust/pull/144#issuecomment-501732431 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6bc2d96a8d01f..5d38d8cb0ccc3 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ make make install # Register the toolchain with rustup -rustup toolchain link avr-toolchain $(realpath $(find . -name 'stage1')) +rustup toolchain link avr-toolchain $(realpath $(find . -name 'stage2')) # Optionally enable the avr toolchain globally rustup default avr-toolchain From eb77ef411fe4c4db7a1b497f386fb1afea957d2d Mon Sep 17 00:00:00 2001 From: Laris Qiao Date: Sun, 5 Apr 2020 18:18:17 +0800 Subject: [PATCH 14/14] customize MacOS building and installation --- README.md | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5d38d8cb0ccc3..4d60a8868a7f2 100644 --- a/README.md +++ b/README.md @@ -25,15 +25,44 @@ First make sure you've installed all dependencies for building, as specified in the main Rust repository [here](https://github.com/rust-lang/rust/#building-from-source). Then use the following commands: +### Unix/Linux/*nix + +``` bash +# Grab the avr-rust sources +git clone https://github.com/avr-rust/rust.git --recursive + +# Create a directory to place built files in +mkdir build && cd build + +# Generate Makefile using settings suitable for an experimental compiler +../rust/configure \ + --enable-debug \ + --disable-docs \ + --enable-llvm-assertions \ + --enable-debug-assertions \ + --enable-optimize \ + --enable-llvm-release-debuginfo \ + --experimental-targets=AVR \ + --prefix=/opt/avr-rust + +# Build the compiler, optionally install it to /opt/avr-rust +make +make install + +# Register the toolchain with rustup +rustup toolchain link avr-toolchain $(realpath $(find . -name 'stage2')) + +# Optionally enable the avr toolchain globally +rustup default avr-toolchain +``` ### Notes for macOS The conventional install directory for macOS is `/usr/local/avr-rust` rather than the Linux default `/opt/avr-rust`, so before the steps below, you must: -1. Edit `build/config.toml` to set `prefix = '/usr/local/avr-rust'`. -2. Ensure `/usr/local/avr-rust` exists and has the correct permissions: `sudo mkdir /usr/local/avr-rust && sudo chown $USER:admin /usr/local/avr-rust` +1. ~~Edit `build/config.toml` to set `prefix = '/usr/local/avr-rust'`.~~ +2. Ensure `/usr/local/avr-rust` exists and has the correct permissions: `sudo mkdir /usr/local/avr-rust && sudo chown ${USER}:admin /usr/local/avr-rust` Finally, `realpath` isn't included by default on macOS but is included in GNU Coreutils, so you can either `brew install coreutils` so the `rustup toolchain...` step works properly, or just use the explicit path (`rustup toolchain link avr-toolchain /usr/local/avr-rust`). - ``` bash # Grab the avr-rust sources git clone https://github.com/avr-rust/rust.git --recursive @@ -50,14 +79,14 @@ mkdir build && cd build --enable-optimize \ --enable-llvm-release-debuginfo \ --experimental-targets=AVR \ - --prefix=/opt/avr-rust + --prefix=/usr/local/avr-rust -# Build the compiler, optionally install it to /opt/avr-rust +# Build the compiler, install it to /usr/local/avr-rust make make install # Register the toolchain with rustup -rustup toolchain link avr-toolchain $(realpath $(find . -name 'stage2')) +rustup toolchain link avr-toolchain /usr/local/avr-rust # Optionally enable the avr toolchain globally rustup default avr-toolchain