[tools] abstract-machine CMake build support

This commit is contained in:
xinyangli 2024-07-26 12:18:13 +08:00
parent 45a3dffbc7
commit 6aebc44707
Signed by: xin
SSH key fingerprint: SHA256:qZ/tzd8lYRtUFSrfBDBMcUqV4GHKxqeqRA3huItgvbk
5 changed files with 598 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

2
.gitignore vendored
View file

@ -51,3 +51,5 @@ tags
CMakeLists.txt CMakeLists.txt
cmake-build-debug cmake-build-debug
*.mk *.mk
**/.cache
.direnv

View file

@ -0,0 +1,113 @@
# -- Generated by scons. Add source files in current directory.
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
set(ARCH "riscv-nemu")
find_package(am-${ARCH} REQUIRED)
find_package(klib REQUIRED)
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR virt64)
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
SET(CMAKE_C_COMPILER "/nix/store/nxmr52s1hri63plbhvxcd08g2nxmbjx7-riscv32-none-elf-gcc-wrapper-13.2.0/bin/riscv32-none-elf-gcc")
SET(CMAKE_ASM_COMPILER "/nix/store/nxmr52s1hri63plbhvxcd08g2nxmbjx7-riscv32-none-elf-gcc-wrapper-13.2.0/bin/riscv32-none-elf-gcc")
SET(CMAKE_C_FLAGS "-ffreestanding -flax-vector-conversions -Wno-cpp -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -fdiagnostics-color=always -O0 -ggdb -fvar-tracking ")
SET(CMAKE_ASM_FLAGS " -c -x assembler-with-cpp -D__ASSEMBLY__ -ggdb")
SET(CMAKE_C_COMPILER_WORKS TRUE)
SET(CMAKE_CXX_COMPILER "/nix/store/nxmr52s1hri63plbhvxcd08g2nxmbjx7-riscv32-none-elf-gcc-wrapper-13.2.0/bin/riscv32-none-elf-g++")
SET(CMAKE_CXX_FLAGS "-ffreestanding -flax-vector-conversions -Wno-cpp -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -fdiagnostics-color=always -O0 -ggdb -fvar-tracking ")
SET(CMAKE_CXX_COMPILER_WORKS TRUE)
SET(CMAKE_OBJCOPY "/nix/store/nxmr52s1hri63plbhvxcd08g2nxmbjx7-riscv32-none-elf-gcc-wrapper-13.2.0/bin/riscv32-none-elf-objcopy")
SET(CMAKE_SIZE "/nix/store/nxmr52s1hri63plbhvxcd08g2nxmbjx7-riscv32-none-elf-gcc-wrapper-13.2.0/bin/riscv32-none-elf-size")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections,-Map=rtthread.map,-cref,-u,_start -T ${CMAKE_SOURCE_DIR}/extra.ld -lgcc -static")
SET(CMAKE_CXX_STANDARD 14)
PROJECT(rtthread C CXX ASM)
INCLUDE_DIRECTORIES(
../../components/libc/compilers/common/include
../../components/drivers/include
../../components/dfs/dfs_v1/include
../../components/dfs/dfs_v1/filesystems/devfs
../../components/dfs/dfs_v1/filesystems/elmfat
../../components/dfs/dfs_v1/filesystems/romfs
../../components/finsh
.
../../include
../../components/libc/posix/io/poll
../../components/libc/posix/io/stdio
../../components/libc/posix/ipc
../../components/utilities/utest
../../components/utilities/libadt
)
ADD_DEFINITIONS(
-D__RTTHREAD__
)
SET(PROJECT_SOURCES
../../components/libc/compilers/common/cstring.c
../../components/libc/compilers/common/cwchar.c
../../components/libc/compilers/common/cctype.c
../../components/libc/compilers/common/ctime.c
../../components/libc/compilers/common/cstdio.c
../../components/libc/compilers/common/cstdlib.c
../../components/drivers/cputime/cputime.c
../../components/drivers/cputime/cputimer.c
../../components/drivers/ipc/completion.c
../../components/drivers/ipc/dataqueue.c
../../components/drivers/ipc/pipe.c
../../components/drivers/ipc/ringblk_buf.c
../../components/drivers/ipc/ringbuffer.c
../../components/drivers/ipc/waitqueue.c
../../components/drivers/ipc/workqueue.c
../../components/drivers/misc/rt_null.c
../../components/drivers/misc/rt_random.c
../../components/drivers/misc/rt_zero.c
../../components/drivers/rtc/rtc.c
../../components/drivers/serial/serial.c
../../components/dfs/dfs_v1/filesystems/devfs/devfs.c
../../components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c
../../components/dfs/dfs_v1/filesystems/elmfat/ff.c
../../components/dfs/dfs_v1/filesystems/elmfat/ffunicode.c
../../components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c
../../components/dfs/dfs_v1/filesystems/romfs/romfs.c
../../components/dfs/dfs_v1/src/dfs.c
../../components/dfs/dfs_v1/src/dfs_file.c
../../components/dfs/dfs_v1/src/dfs_fs.c
../../components/dfs/dfs_v1/src/dfs_posix.c
../../components/finsh/shell.c
../../components/finsh/msh_parse.c
../../components/finsh/msh_file.c
../../components/finsh/msh.c
../../components/finsh/cmd.c
../../src/clock.c
../../src/components.c
../../src/device.c
../../src/idle.c
../../src/ipc.c
../../src/irq.c
../../src/kservice.c
../../src/mem.c
../../src/mempool.c
../../src/object.c
../../src/scheduler_up.c
../../src/thread.c
../../src/timer.c
../../components/utilities/utest/utest.c
../../components/utilities/libadt/avl.c
../src/context.c
../src/hello.c
../src/interrupt.c
../src/libc.c
../src/uart.c
../src/init.c
)
ADD_EXECUTABLE(${CMAKE_PROJECT_NAME}.elf ${PROJECT_SOURCES})
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME}.elf PRIVATE klib am-${ARCH})
ADD_CUSTOM_COMMAND(TARGET ${CMAKE_PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} --set-section-flags .bss=alloc,load,contents -O binary ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.bin
COMMAND ${CMAKE_SIZE} ${CMAKE_PROJECT_NAME}.elf)

431
flake.lock generated Normal file
View file

@ -0,0 +1,431 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-compat_2": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1709126324,
"narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "d465f4819400de7c8d874d50b982301f28a84605",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_3": {
"inputs": {
"systems": "systems_3"
},
"locked": {
"lastModified": 1709126324,
"narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "d465f4819400de7c8d874d50b982301f28a84605",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_4": {
"inputs": {
"systems": "systems_4"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"gitignore_2": {
"inputs": {
"nixpkgs": [
"ysyx",
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1709237383,
"narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-circt162": {
"locked": {
"lastModified": 1705645507,
"narHash": "sha256-tX3vipIAmNDBA8WNWG4oY4KyTfnm2YieTHO2BhG8ISA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "7995cae3ad60e3d6931283d650d7f43d31aaa5c7",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "7995cae3ad60e3d6931283d650d7f43d31aaa5c7",
"type": "github"
}
},
"nixpkgs-circt162_2": {
"locked": {
"lastModified": 1705645507,
"narHash": "sha256-tX3vipIAmNDBA8WNWG4oY4KyTfnm2YieTHO2BhG8ISA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "7995cae3ad60e3d6931283d650d7f43d31aaa5c7",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "7995cae3ad60e3d6931283d650d7f43d31aaa5c7",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1710695816,
"narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "614b4613980a522ba49f0d194531beddbb7220d3",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-stable_2": {
"locked": {
"lastModified": 1710695816,
"narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "614b4613980a522ba49f0d194531beddbb7220d3",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1709237383,
"narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nur-xin": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1721457008,
"narHash": "sha256-ekpve0om5hzC1Ntd3zm1cZ9oS5pnr7a2n/tueyqFOsg=",
"ref": "refs/heads/master",
"rev": "e7aa3319d52fa987ac2192f63aef3dcb1b057e3a",
"revCount": 151,
"type": "git",
"url": "https://git.xinyang.life/xin/nur.git"
},
"original": {
"type": "git",
"url": "https://git.xinyang.life/xin/nur.git"
}
},
"nur-xin_2": {
"inputs": {
"nixpkgs": [
"ysyx",
"nixpkgs"
]
},
"locked": {
"lastModified": 1721891452,
"narHash": "sha256-2c9nDuXXARzoRXE67lte5kKBeFb1XmTNsvdiIbRUEgE=",
"ref": "refs/heads/master",
"rev": "de8ad578fc4fe527772cec23a7f660bde14c8570",
"revCount": 152,
"type": "git",
"url": "https://git.xinyang.life/xin/nur.git"
},
"original": {
"type": "git",
"url": "https://git.xinyang.life/xin/nur.git"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils_2",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1712055707,
"narHash": "sha256-4XLvuSIDZJGS17xEwSrNuJLL7UjDYKGJSbK1WWX2AK8=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "e35aed5fda3cc79f88ed7f1795021e559582093a",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"pre-commit-hooks_2": {
"inputs": {
"flake-compat": "flake-compat_2",
"flake-utils": "flake-utils_4",
"gitignore": "gitignore_2",
"nixpkgs": [
"ysyx",
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable_2"
},
"locked": {
"lastModified": 1712055707,
"narHash": "sha256-4XLvuSIDZJGS17xEwSrNuJLL7UjDYKGJSbK1WWX2AK8=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "e35aed5fda3cc79f88ed7f1795021e559582093a",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"nixpkgs-circt162": "nixpkgs-circt162",
"nur-xin": "nur-xin",
"pre-commit-hooks": "pre-commit-hooks",
"ysyx": "ysyx"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_3": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_4": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"ysyx": {
"inputs": {
"flake-utils": "flake-utils_3",
"nixpkgs": "nixpkgs_2",
"nixpkgs-circt162": "nixpkgs-circt162_2",
"nur-xin": "nur-xin_2",
"pre-commit-hooks": "pre-commit-hooks_2"
},
"locked": {
"lastModified": 1721901390,
"narHash": "sha256-dkvGoN41OwOWesuPjr+pPXHALNrg7c6CTxSsdF7r+CU=",
"owner": "xinyangli",
"repo": "ysyx-workbench",
"rev": "c9ad69a32dcc4edc9531c5385a55a74819019416",
"type": "github"
},
"original": {
"owner": "xinyangli",
"repo": "ysyx-workbench",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

51
flake.nix Normal file
View file

@ -0,0 +1,51 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-circt162.url = "github:NixOS/nixpkgs/7995cae3ad60e3d6931283d650d7f43d31aaa5c7";
flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
nur-xin = {
url = "git+https://git.xinyang.life/xin/nur.git";
inputs.nixpkgs.follows = "nixpkgs";
};
ysyx = {
url = "github:xinyangli/ysyx-workbench";
};
};
outputs = { self, ... }@inputs: with inputs;
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
rv32CrossConfig = import nixpkgs {
localSystem = system;
crossSystem = {
config = "riscv32-none-elf";
gcc = {
abi = "ilp32";
arch = "rv32if";
};
};
};
in
{
devShells.default = rv32CrossConfig.mkShell {
nativeBuildInputs = with pkgs; [
scons
cmake
ninja
];
buildInputs = [
inputs.ysyx.packages.${system}.rv32Cross.abstract-machine
];
};
}
);
}