Skip to content

Commit bfc27ff

Browse files
committed
add mos-unknown-none target
do not use patched cargo update cargo
1 parent 5257aee commit bfc27ff

25 files changed

+828
-4
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker/llvm-mos
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: build_docker_images
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
llvm_base_image_tag:
6+
description: 'llvm-mos base image tag'
7+
required: true
8+
default: 'ca75934d2-da558fc'
9+
10+
jobs:
11+
create_docker_images:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Set up QEMU
15+
uses: docker/setup-qemu-action@v2
16+
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
20+
- name: Set rust-mos short sha
21+
id: rust_mos
22+
run: echo -e "::set-output name=short_sha::$(git rev-parse --short HEAD)"
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v1
26+
- name: Login to DockerHub
27+
uses: docker/login-action@v1
28+
with:
29+
username: ${{ secrets.DOCKERHUB_USERNAME }}
30+
password: ${{ secrets.DOCKERHUB_TOKEN }}
31+
# - name: Build and push rust-mos
32+
# id: docker_build_3
33+
# uses: docker/build-push-action@v2
34+
# with:
35+
# push: true
36+
# tags: mrkits/rust-mos:${{ github.event.inputs.llvm_base_image_tag }}-${{ steps.rust_mos.outputs.short_sha }}-dist
37+
# file: docker/rust-mos/Dockerfile
38+
# context: .
39+
# build-args: |
40+
# LLVM_MOS_IMAGE=mrkits/llvm-mos:${{ github.event.inputs.llvm_base_image_tag }}
41+
42+
- name: Build and push multi-platform rust-mos image
43+
id: docker_build_3
44+
uses: docker/build-push-action@v2
45+
with:
46+
push: true
47+
tags: mrkits/rust-mos:${{ github.event.inputs.llvm_base_image_tag }}-${{ steps.rust_mos.outputs.short_sha }}
48+
file: docker/rust-mos/Dockerfile.multiarch
49+
platforms: linux/amd64,linux/arm64
50+
context: docker/rust-mos/
51+
build-args: |
52+
LLVM_MOS_IMAGE=mrkits/llvm-mos:${{ github.event.inputs.llvm_base_image_tag }}
53+
RUST_MOS_DIST_IMAGE=mrkits/rust-mos:ca75934d2-da558fc-ad5d187a-dist
54+
# RUST_MOS_DIST_IMAGE=mrkits/rust-mos:${{ github.event.inputs.llvm_base_image_tag }}-${{ steps.rust_mos.outputs.short_sha }}-dist
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: llvm_mos_amd64
2+
on:
3+
workflow_call:
4+
inputs:
5+
arch:
6+
description: architecture
7+
default: 'amd64'
8+
type: string
9+
llvm_mos_repo:
10+
description: 'llvm-mos repo'
11+
default: 'mrk-its/llvm-mos'
12+
type: string
13+
llvm_mos_sdk_repo:
14+
description: 'llvm-mos-sdk repo'
15+
default: 'mrk-its/llvm-mos-sdk'
16+
type: string
17+
llvm_mos_ref:
18+
description: 'llvm-mos ref'
19+
default: 'main'
20+
type: string
21+
llvm_mos_sdk_ref:
22+
description: 'llvm-mos-sdk ref'
23+
default: 'main'
24+
type: string
25+
26+
jobs:
27+
cross_build_llvm:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Set up QEMU
31+
uses: docker/setup-qemu-action@v2
32+
33+
- name: Checkout
34+
uses: actions/checkout@v3
35+
36+
- name: Checkout llvm-mos
37+
uses: actions/checkout@v3
38+
with:
39+
repository: ${{ inputs.llvm_mos_repo }}
40+
path: docker/llvm-mos/llvm-mos
41+
ref: ${{ inputs.llvm_mos_ref }}
42+
43+
- name: Checkout llvm-mos-sdk
44+
uses: actions/checkout@v3
45+
with:
46+
repository: ${{ inputs.llvm_mos_sdk_repo }}
47+
path: docker/llvm-mos/llvm-mos-sdk
48+
ref: ${{inputs.llvm_mos_sdk_ref }}
49+
50+
- name: Set short sha
51+
id: short_sha
52+
run: echo -e "::set-output name=llvm_mos::$(cd docker/llvm-mos/llvm-mos; git rev-parse --short HEAD)\n::set-output name=llvm_mos_sdk::$(cd docker/llvm-mos/llvm-mos-sdk; git rev-parse --short HEAD)"
53+
54+
- name: Check outputs
55+
run: echo ${{ steps.short_sha.outputs.llvm_mos }} ${{ steps.short_sha.outputs.llvm_mos_sdk }}
56+
57+
- name: Set up Docker Buildx
58+
uses: docker/setup-buildx-action@v1
59+
- name: Login to DockerHub
60+
uses: docker/login-action@v1
61+
with:
62+
username: ${{ secrets.DOCKERHUB_USERNAME }}
63+
password: ${{ secrets.DOCKERHUB_TOKEN }}
64+
- name: Build and push llvm-mos
65+
id: docker_build_1
66+
uses: docker/build-push-action@v2
67+
with:
68+
push: true
69+
tags: mrkits/llvm-mos:${{ steps.short_sha.outputs.llvm_mos }}-${{ steps.short_sha.outputs.llvm_mos_sdk }}-${{inputs.arch}}
70+
build-args: TARGETARCH=${{ inputs.arch }}
71+
platforms: ${{ inputs.arch }}
72+
context: docker/llvm-mos
73+
cache-from: type=registry,ref=mrkits/llvm-mos:${{ steps.short_sha.outputs.llvm_mos }}-${{ steps.short_sha.outputs.llvm_mos_sdk }}-${{inputs.arch}}
74+
# cache-to: type=registry,ref=mrkits/llvm-mos:llvm-mos-buildcache-${{matrix.arch}},mode=max

.github/workflows/cross-build.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: llvm_cross_build
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
llvm_mos_repo:
6+
description: 'llvm-mos repo'
7+
default: 'llvm-mos/llvm-mos'
8+
type: string
9+
llvm_mos_sdk_repo:
10+
description: 'llvm-mos-sdk repo'
11+
default: 'llvm-mos/llvm-mos-sdk'
12+
type: string
13+
llvm_mos_ref:
14+
description: 'llvm-mos ref'
15+
default: 'adbc7b3dd18b8a8a0bbd69c50f33b3b07ec0abf5'
16+
type: string
17+
llvm_mos_sdk_ref:
18+
description: 'llvm-mos-sdk ref'
19+
default: '3e94be457ceece85739853e118c67a1d82450f4f'
20+
type: string
21+
22+
jobs:
23+
amd64_image:
24+
if: ${{ false }}
25+
uses: ./.github/workflows/cross-build-llvm-mos.yml
26+
with:
27+
arch: amd64
28+
llvm_mos_repo: ${{ github.event.inputs.llvm_mos_repo }}
29+
llvm_mos_sdk_repo: ${{ github.event.inputs.llvm_mos_sdk_repo }}
30+
llvm_mos_ref: ${{ github.event.inputs.llvm_mos_ref }}
31+
llvm_mos_sdk_ref: ${{ github.event.inputs.llvm_mos_sdk_ref }}
32+
secrets: inherit
33+
34+
arm64_image:
35+
if: ${{ false }}
36+
uses: ./.github/workflows/cross-build-llvm-mos.yml
37+
with:
38+
arch: arm64
39+
llvm_mos_repo: ${{ github.event.inputs.llvm_mos_repo }}
40+
llvm_mos_sdk_repo: ${{ github.event.inputs.llvm_mos_sdk_repo }}
41+
llvm_mos_ref: ${{ github.event.inputs.llvm_mos_ref }}
42+
llvm_mos_sdk_ref: ${{ github.event.inputs.llvm_mos_sdk_ref }}
43+
secrets: inherit
44+
45+
final:
46+
runs-on: ubuntu-latest
47+
# needs:
48+
# - amd64_image
49+
# - arm64_image
50+
steps:
51+
- name: Set up QEMU
52+
uses: docker/setup-qemu-action@v2
53+
54+
- name: Checkout
55+
uses: actions/checkout@v3
56+
57+
- name: Checkout llvm-mos
58+
uses: actions/checkout@v3
59+
with:
60+
repository: ${{ github.event.inputs.llvm_mos_repo }}
61+
path: docker/llvm-mos/llvm-mos
62+
ref: ${{ github.event.inputs.llvm_mos_ref }}
63+
64+
- name: Checkout llvm-mos-sdk
65+
uses: actions/checkout@v3
66+
with:
67+
repository: ${{ github.event.inputs.llvm_mos_sdk_repo }}
68+
path: docker/llvm-mos/llvm-mos-sdk
69+
ref: ${{github.event.inputs.llvm_mos_sdk_ref }}
70+
71+
- name: Set short sha
72+
id: short_sha
73+
run: echo -e "::set-output name=llvm_mos::$(cd docker/llvm-mos/llvm-mos; git rev-parse --short HEAD)\n::set-output name=llvm_mos_sdk::$(cd docker/llvm-mos/llvm-mos-sdk; git rev-parse --short HEAD)"
74+
75+
- name: Set rust-mos short sha
76+
id: rust_mos
77+
run: echo -e "::set-output name=short_sha::$(git rev-parse --short HEAD)"
78+
# run: echo -e "::set-output name=short_sha::ad5d187a"
79+
80+
- name: show revisions
81+
run: "echo llvm_mos: ${{ steps.short_sha.outputs.llvm_mos }} llvm_mos_sdk: ${{ steps.short_sha.outputs.llvm_mos_sdk }} rust_mos: ${{ steps.rust_mos.outputs.short_sha }}"
82+
83+
- name: Set up Docker Buildx
84+
uses: docker/setup-buildx-action@v1
85+
86+
- name: Login to DockerHub
87+
uses: docker/login-action@v1
88+
with:
89+
username: ${{ secrets.DOCKERHUB_USERNAME }}
90+
password: ${{ secrets.DOCKERHUB_TOKEN }}
91+
92+
- name: Build and push rust-mos
93+
id: build_rust_dist_image
94+
uses: docker/build-push-action@v2
95+
with:
96+
push: true
97+
tags: mrkits/rust-mos:${{ steps.short_sha.outputs.llvm_mos }}-${{ steps.short_sha.outputs.llvm_mos_sdk }}-${{ steps.rust_mos.outputs.short_sha }}-dist
98+
file: docker/rust-mos/Dockerfile
99+
context: .
100+
build-args: |
101+
LLVM_MOS_IMAGE=mrkits/llvm-mos:${{ steps.short_sha.outputs.llvm_mos }}-${{ steps.short_sha.outputs.llvm_mos_sdk }}
102+
cache-from: type=registry,ref=mrkits/rust-mos:${{ steps.short_sha.outputs.llvm_mos }}-${{ steps.short_sha.outputs.llvm_mos_sdk }}-${{ steps.rust_mos.outputs.short_sha }}-dist
103+
104+
- name: Build and push multi-platform rust-mos image
105+
id: build_rust_multiarch_image
106+
uses: docker/build-push-action@v2
107+
with:
108+
push: true
109+
tags: mrkits/rust-mos:${{ steps.short_sha.outputs.llvm_mos }}-${{ steps.short_sha.outputs.llvm_mos_sdk }}-${{ steps.rust_mos.outputs.short_sha }}
110+
file: docker/rust-mos/Dockerfile.multiarch
111+
platforms: linux/amd64
112+
#,linux/arm64
113+
context: docker/rust-mos/
114+
build-args: |
115+
LLVM_MOS_IMAGE=mrkits/llvm-mos:${{ steps.short_sha.outputs.llvm_mos }}-${{ steps.short_sha.outputs.llvm_mos_sdk }}
116+
RUST_MOS_DIST_IMAGE=mrkits/rust-mos:${{ steps.short_sha.outputs.llvm_mos }}-${{ steps.short_sha.outputs.llvm_mos_sdk }}-${{ steps.rust_mos.outputs.short_sha }}-dist
117+

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,50 @@ If you wish to _contribute_ to the compiler, you should read
2323

2424
</details>
2525

26+
# MOS target notes
27+
28+
MOS target depends on [llvm-mos](https://github.com/llvm-mos/llvm-mos) and [llvm-mos-sdk](https://github.com/llvm-mos/llvm-mos-sdk). Installation of llvm-mos is described in project's [README](https://github.com/llvm-mos/llvm-mos/blob/main/README.md), but it needs to be slightly modified:
29+
30+
```
31+
git clone https://github.com/llvm-mos/llvm-mos
32+
cd llvm-mos
33+
# For MacOS, use `-DLIBXML2_LIBRARY=/usr/local/opt/libxml2/lib/libxml2.dylib` instead of `-DLIBXML2_LIBRARY=/usr/lib/x86_64-linux-gnu/libxml2.so`
34+
cmake -C clang/cmake/caches/MOS.cmake -G "Ninja" -S llvm -B build \
35+
-DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF \
36+
-DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON \
37+
-DLLVM_INSTALL_UTILS=ON -DLLVM_BUILD_UTILS=ON -DLLVM_TOOLCHAIN_UTILITIES=FileCheck \
38+
-DLLVM_TOOLCHAIN_TOOLS="llvm-addr2line;llvm-ar;llvm-cxxfilt;llvm-dwarfdump;llvm-mc;llvm-nm;llvm-objcopy;llvm-objdump;llvm-ranlib;llvm-readelf;llvm-readobj;llvm-size;llvm-strings;llvm-strip;llvm-symbolizer;llvm-config;llc" \
39+
-DLIBXML2_LIBRARY=/usr/lib/x86_64-linux-gnu/libxml2.so \
40+
-DLLVM_TARGETS_TO_BUILD="MOS;X86" \
41+
-DLLVM_ENABLE_PROJECTS="clang;lld;lldb"
42+
cmake --build build -t install
43+
```
44+
45+
Build & install llvm-mos-sdk:
46+
47+
```
48+
git clone https://github.com/llvm-mos/llvm-mos-sdk
49+
cd llvm-mos-sdk
50+
cmake -G "Ninja" -B build
51+
cmake --build build -t install
52+
```
53+
54+
And finally build rust mos toolchain:
55+
```
56+
export RUST_TARGET_PATH=/usr/local/rust-mos-targets/
57+
cp config.toml.example config.toml
58+
# in config.toml adjust path to llvm-config
59+
# if llvm-mos is installed to other than /usr/local prefix
60+
./x.py build -i --stage 0 src/tools/cargo
61+
./x.py build -i && (
62+
ln -s ../../stage0-tools-bin/cargo build/x86_64-unknown-linux-gnu/stage1/bin/cargo
63+
rustup toolchain link mos build/x86_64-unknown-linux-gnu/stage1
64+
rustup default mos
65+
mkdir -p $RUST_TARGET_PATH
66+
python3 create_mos_targets.py $RUST_TARGET_PATH
67+
)
68+
```
69+
2670
## Quick Start
2771

2872
Read ["Installation"] from [The Book].

build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
./x.py build -i --stage 0 src/tools/cargo
2+
./x.py build -i && (
3+
ln -s ../../stage0-tools-bin/cargo build/x86_64-unknown-linux-gnu/stage1/bin/cargo
4+
rustup toolchain link mos build/x86_64-unknown-linux-gnu/stage1
5+
rustup default mos
6+
mkdir -p $RUST_TARGET_PATH
7+
python3 create_mos_targets.py $RUST_TARGET_PATH
8+
)

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ impl<'ll> CodegenCx<'ll, '_> {
924924
// recognize it like one (including turning it into `bcmp` sometimes)
925925
// and we use it to implement intrinsics like `raw_eq` and `compare_bytes`
926926
match self.sess().target.arch.as_ref() {
927-
"avr" | "msp430" => ifn!("memcmp", fn(ptr, ptr, t_isize) -> t_i16),
927+
"avr" | "msp430" | "mos" => ifn!("memcmp", fn(ptr, ptr, t_isize) -> t_i16),
928928
_ => ifn!("memcmp", fn(ptr, ptr, t_isize) -> t_i32),
929929
}
930930

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
179179
addr_ops.push(direct_offset.bytes() as u64);
180180
}
181181
for &offset in indirect_offsets {
182-
addr_ops.push(op_deref());
182+
addr_ops.push(op_deref() as u64);
183183
if offset.bytes() > 0 {
184184
addr_ops.push(op_plus_uconst());
185185
addr_ops.push(offset.bytes() as u64);

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
342342
let n = self.const_usize(layout.size().bytes());
343343
let cmp = self.call_intrinsic("memcmp", &[a, b, n]);
344344
match self.cx.sess().target.arch.as_ref() {
345-
"avr" | "msp430" => self.icmp(IntPredicate::IntEQ, cmp, self.const_i16(0)),
345+
"avr" | "msp430" | "mos" => self.icmp(IntPredicate::IntEQ, cmp, self.const_i16(0)),
346346
_ => self.icmp(IntPredicate::IntEQ, cmp, self.const_i32(0)),
347347
}
348348
}

compiler/rustc_llvm/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const OPTIONAL_COMPONENTS: &[&str] = &[
1414
"m68k",
1515
"csky",
1616
"mips",
17+
"mos",
1718
"powerpc",
1819
"systemz",
1920
"jsbackend",

compiler/rustc_llvm/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ pub fn initialize_available_targets() {
6363
LLVMInitializeX86AsmPrinter,
6464
LLVMInitializeX86AsmParser
6565
);
66+
init_target!(
67+
llvm_component = "mos",
68+
LLVMInitializeMOSTargetInfo,
69+
LLVMInitializeMOSTarget,
70+
LLVMInitializeMOSTargetMC,
71+
LLVMInitializeMOSAsmPrinter,
72+
LLVMInitializeMOSAsmParser
73+
);
6674
init_target!(
6775
llvm_component = "arm",
6876
LLVMInitializeARMTargetInfo,

compiler/rustc_target/src/abi/call/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mod wasm;
2828
mod x86;
2929
mod x86_64;
3030
mod x86_win64;
31+
mod mos;
3132

3233
#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
3334
pub enum PassMode {
@@ -832,6 +833,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
832833
"csky" => csky::compute_abi_info(self),
833834
"mips" | "mips32r6" => mips::compute_abi_info(cx, self),
834835
"mips64" | "mips64r6" => mips64::compute_abi_info(cx, self),
836+
"mos" => mos::compute_abi_info(self),
835837
"powerpc" => powerpc::compute_abi_info(self),
836838
"powerpc64" => powerpc64::compute_abi_info(cx, self),
837839
"s390x" => s390x::compute_abi_info(cx, self),

0 commit comments

Comments
 (0)