mirror of
https://github.com/raspberrypi/pico-sdk.git
synced 2026-03-14 21:19:43 +01:00
Add scripts to bazel build
Use new include_linker_script_dir and use_linker_script_file functions to add the linker arguments
This commit is contained in:
parent
ce69db060a
commit
988d8169db
6 changed files with 244 additions and 14 deletions
49
bazel/util/pico_linker_scripts.bzl
Normal file
49
bazel/util/pico_linker_scripts.bzl
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "use_cpp_toolchain")
|
||||
|
||||
def _include_linker_script_dir_impl(ctx):
|
||||
link_include_dir = str(ctx.label.package)
|
||||
depset_direct = ["-L" + str(link_include_dir)]
|
||||
if len(ctx.files.use_scripts):
|
||||
for script in ctx.files.use_scripts:
|
||||
depset_direct.append("-T" + str(script.path))
|
||||
|
||||
linking_inputs = cc_common.create_linker_input(
|
||||
owner = ctx.label,
|
||||
user_link_flags = depset(
|
||||
direct = depset_direct,
|
||||
),
|
||||
)
|
||||
return [
|
||||
CcInfo(linking_context = cc_common.create_linking_context(linker_inputs = depset(direct = [linking_inputs]))),
|
||||
]
|
||||
|
||||
include_linker_script_dir = rule(
|
||||
implementation = _include_linker_script_dir_impl,
|
||||
attrs = {
|
||||
"use_scripts": attr.label_list(allow_files = [".ld"]),
|
||||
},
|
||||
toolchains = use_cpp_toolchain(),
|
||||
fragments = ["cpp"],
|
||||
)
|
||||
|
||||
def _use_linker_script_file_impl(ctx):
|
||||
link_file = ctx.file.script.path
|
||||
|
||||
linking_inputs = cc_common.create_linker_input(
|
||||
owner = ctx.label,
|
||||
user_link_flags = depset(
|
||||
direct = ["-T" + str(link_file)],
|
||||
),
|
||||
)
|
||||
return [
|
||||
CcInfo(linking_context = cc_common.create_linking_context(linker_inputs = depset(direct = [linking_inputs]))),
|
||||
]
|
||||
|
||||
use_linker_script_file = rule(
|
||||
implementation = _use_linker_script_file_impl,
|
||||
attrs = {
|
||||
"script": attr.label(mandatory = True, allow_single_file = [".ld"]),
|
||||
},
|
||||
toolchains = use_cpp_toolchain(),
|
||||
fragments = ["cpp"],
|
||||
)
|
||||
|
|
@ -2,6 +2,8 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
|||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load("//bazel/util:pico_linker_scripts.bzl", "use_linker_script_file")
|
||||
|
||||
exports_files(
|
||||
[
|
||||
"memmap_blocked_ram.ld",
|
||||
|
|
@ -11,6 +13,26 @@ exports_files(
|
|||
],
|
||||
)
|
||||
|
||||
use_linker_script_file(
|
||||
name = "memmap_default_args",
|
||||
script = "memmap_default.ld",
|
||||
)
|
||||
|
||||
use_linker_script_file(
|
||||
name = "memmap_blocked_ram_args",
|
||||
script = "memmap_blocked_ram.ld",
|
||||
)
|
||||
|
||||
use_linker_script_file(
|
||||
name = "memmap_copy_to_ram_args",
|
||||
script = "memmap_copy_to_ram.ld",
|
||||
)
|
||||
|
||||
use_linker_script_file(
|
||||
name = "memmap_no_flash_args",
|
||||
script = "memmap_no_flash.ld",
|
||||
)
|
||||
|
||||
# It's possible to set linker scripts globally or on a per-binary basis.
|
||||
#
|
||||
# Setting globally:
|
||||
|
|
@ -22,12 +44,14 @@ exports_files(
|
|||
# * Manually add your desired linker script to each cc_binary.
|
||||
cc_library(
|
||||
name = "default_linker_script",
|
||||
linkopts = ["-T$(location memmap_default.ld)"],
|
||||
target_compatible_with = ["//bazel/constraint:rp2040"],
|
||||
deps = [
|
||||
"memmap_default.ld",
|
||||
"//src/rp2_common/pico_crt0:no_warn_rwx_flag",
|
||||
"//src/rp2_common/pico_crt0/rp2040/scripts:rp2040_linker_scripts",
|
||||
"//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts",
|
||||
"//src/rp2_common/pico_standard_link:default_flash_region",
|
||||
"memmap_default.ld",
|
||||
"memmap_default_args",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
@ -35,12 +59,14 @@ cc_library(
|
|||
cc_library(
|
||||
name = "blocked_ram_linker_script",
|
||||
defines = ["PICO_USE_BLOCKED_RAM=1"],
|
||||
linkopts = ["-T$(location memmap_blocked_ram.ld)"],
|
||||
target_compatible_with = ["//bazel/constraint:rp2040"],
|
||||
deps = [
|
||||
"memmap_blocked_ram.ld",
|
||||
"//src/rp2_common/pico_crt0:no_warn_rwx_flag",
|
||||
"//src/rp2_common/pico_crt0/rp2040/scripts:rp2040_linker_scripts",
|
||||
"//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts",
|
||||
"//src/rp2_common/pico_standard_link:default_flash_region",
|
||||
"memmap_blocked_ram.ld",
|
||||
"memmap_blocked_ram_args",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
@ -48,12 +74,14 @@ cc_library(
|
|||
cc_library(
|
||||
name = "copy_to_ram_linker_script",
|
||||
defines = ["PICO_COPY_TO_RAM=1"],
|
||||
linkopts = ["-T$(location memmap_copy_to_ram.ld)"],
|
||||
target_compatible_with = ["//bazel/constraint:rp2040"],
|
||||
deps = [
|
||||
"memmap_copy_to_ram.ld",
|
||||
"//src/rp2_common/pico_crt0:no_warn_rwx_flag",
|
||||
"//src/rp2_common/pico_crt0/rp2040/scripts:rp2040_linker_scripts",
|
||||
"//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts",
|
||||
"//src/rp2_common/pico_standard_link:default_flash_region",
|
||||
"memmap_copy_to_ram.ld",
|
||||
"memmap_copy_to_ram_args",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
@ -61,10 +89,12 @@ cc_library(
|
|||
cc_library(
|
||||
name = "no_flash_linker_script",
|
||||
defines = ["PICO_NO_FLASH=1"],
|
||||
linkopts = ["-T$(location memmap_no_flash.ld)"],
|
||||
target_compatible_with = ["//bazel/constraint:rp2040"],
|
||||
deps = [
|
||||
"memmap_no_flash.ld",
|
||||
"//src/rp2_common/pico_crt0:no_warn_rwx_flag",
|
||||
"//src/rp2_common/pico_crt0/rp2040/scripts:rp2040_linker_scripts",
|
||||
"//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts",
|
||||
"memmap_no_flash.ld",
|
||||
"memmap_no_flash_args",
|
||||
],
|
||||
)
|
||||
|
|
|
|||
31
src/rp2_common/pico_crt0/rp2040/scripts/BUILD.bazel
Normal file
31
src/rp2_common/pico_crt0/rp2040/scripts/BUILD.bazel
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load("//bazel/util:pico_linker_scripts.bzl", "include_linker_script_dir")
|
||||
|
||||
exports_files(
|
||||
[
|
||||
"default_locations.ld",
|
||||
"section_copy_to_ram_text.ld",
|
||||
"section_default_text.ld",
|
||||
"section_no_flash_text.ld",
|
||||
"section_platform_end.ld",
|
||||
]
|
||||
)
|
||||
|
||||
include_linker_script_dir(
|
||||
name = "rp2040_linker_script_args",
|
||||
use_scripts = ["default_locations.ld"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "rp2040_linker_scripts",
|
||||
target_compatible_with = ["//bazel/constraint:rp2040"],
|
||||
deps = [
|
||||
"default_locations.ld",
|
||||
"section_copy_to_ram_text.ld",
|
||||
"section_default_text.ld",
|
||||
"section_no_flash_text.ld",
|
||||
"section_platform_end.ld",
|
||||
"rp2040_linker_script_args",
|
||||
],
|
||||
)
|
||||
|
|
@ -2,6 +2,8 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
|||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load("//bazel/util:pico_linker_scripts.bzl", "use_linker_script_file")
|
||||
|
||||
exports_files(
|
||||
[
|
||||
"memmap_copy_to_ram.ld",
|
||||
|
|
@ -10,6 +12,26 @@ exports_files(
|
|||
],
|
||||
)
|
||||
|
||||
use_linker_script_file(
|
||||
name = "memmap_default_args",
|
||||
script = "memmap_default.ld",
|
||||
)
|
||||
|
||||
use_linker_script_file(
|
||||
name = "memmap_blocked_ram_args",
|
||||
script = "memmap_blocked_ram.ld",
|
||||
)
|
||||
|
||||
use_linker_script_file(
|
||||
name = "memmap_copy_to_ram_args",
|
||||
script = "memmap_copy_to_ram.ld",
|
||||
)
|
||||
|
||||
use_linker_script_file(
|
||||
name = "memmap_no_flash_args",
|
||||
script = "memmap_no_flash.ld",
|
||||
)
|
||||
|
||||
# It's possible to set linker scripts globally or on a per-binary basis.
|
||||
#
|
||||
# Setting globally:
|
||||
|
|
@ -21,12 +43,14 @@ exports_files(
|
|||
# * Manually add your desired linker script to each cc_binary.
|
||||
cc_library(
|
||||
name = "default_linker_script",
|
||||
linkopts = ["-T$(location memmap_default.ld)"],
|
||||
target_compatible_with = ["//bazel/constraint:rp2350"],
|
||||
deps = [
|
||||
"memmap_default.ld",
|
||||
"//src/rp2_common/pico_crt0:no_warn_rwx_flag",
|
||||
"//src/rp2_common/pico_crt0/rp2350/scripts:rp2350_linker_scripts",
|
||||
"//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts",
|
||||
"//src/rp2_common/pico_standard_link:default_flash_region",
|
||||
"memmap_default.ld",
|
||||
"memmap_default_args",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
@ -34,12 +58,14 @@ cc_library(
|
|||
cc_library(
|
||||
name = "copy_to_ram_linker_script",
|
||||
defines = ["PICO_COPY_TO_RAM=1"],
|
||||
linkopts = ["-T$(location memmap_copy_to_ram.ld)"],
|
||||
target_compatible_with = ["//bazel/constraint:rp2350"],
|
||||
deps = [
|
||||
"memmap_copy_to_ram.ld",
|
||||
"//src/rp2_common/pico_crt0:no_warn_rwx_flag",
|
||||
"//src/rp2_common/pico_crt0/rp2350/scripts:rp2350_linker_scripts",
|
||||
"//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts",
|
||||
"//src/rp2_common/pico_standard_link:default_flash_region",
|
||||
"memmap_copy_to_ram.ld",
|
||||
"memmap_copy_to_ram_args",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
@ -47,10 +73,12 @@ cc_library(
|
|||
cc_library(
|
||||
name = "no_flash_linker_script",
|
||||
defines = ["PICO_NO_FLASH=1"],
|
||||
linkopts = ["-T$(location memmap_no_flash.ld)"],
|
||||
target_compatible_with = ["//bazel/constraint:rp2350"],
|
||||
deps = [
|
||||
"memmap_no_flash.ld",
|
||||
"//src/rp2_common/pico_crt0:no_warn_rwx_flag",
|
||||
"//src/rp2_common/pico_crt0/rp2350/scripts:rp2350_linker_scripts",
|
||||
"//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts",
|
||||
"memmap_no_flash.ld",
|
||||
"memmap_no_flash_args",
|
||||
],
|
||||
)
|
||||
|
|
|
|||
31
src/rp2_common/pico_crt0/rp2350/scripts/BUILD.bazel
Normal file
31
src/rp2_common/pico_crt0/rp2350/scripts/BUILD.bazel
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load("//bazel/util:pico_linker_scripts.bzl", "include_linker_script_dir")
|
||||
|
||||
exports_files(
|
||||
[
|
||||
"default_locations.ld",
|
||||
"section_copy_to_ram_text.ld",
|
||||
"section_default_text.ld",
|
||||
"section_no_flash_text.ld",
|
||||
"section_platform_end.ld",
|
||||
]
|
||||
)
|
||||
|
||||
include_linker_script_dir(
|
||||
name = "rp2350_linker_script_args",
|
||||
use_scripts = ["default_locations.ld"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "rp2350_linker_scripts",
|
||||
target_compatible_with = ["//bazel/constraint:rp2350"],
|
||||
deps = [
|
||||
"default_locations.ld",
|
||||
"section_copy_to_ram_text.ld",
|
||||
"section_default_text.ld",
|
||||
"section_no_flash_text.ld",
|
||||
"section_platform_end.ld",
|
||||
"rp2350_linker_script_args",
|
||||
],
|
||||
)
|
||||
61
src/rp2_common/pico_standard_link/scripts/BUILD.bazel
Normal file
61
src/rp2_common/pico_standard_link/scripts/BUILD.bazel
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
load("//bazel:defs.bzl", "compatible_with_rp2")
|
||||
load("//bazel/util:pico_linker_scripts.bzl", "include_linker_script_dir")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
exports_files(
|
||||
[
|
||||
"memory_aliases_default.ld",
|
||||
"memory_aliases_no_flash.ld",
|
||||
"memory_flash.ld",
|
||||
"memory_ram.ld",
|
||||
"memory_scratch.ld",
|
||||
"memory_xip_ram.ld",
|
||||
"section_copy_to_ram_data.ld",
|
||||
"section_default_data.ld",
|
||||
"section_end.ld",
|
||||
"section_flash_end.ld",
|
||||
"section_heap.ld",
|
||||
"section_no_flash_data.ld",
|
||||
"sections_copy_to_ram.ld",
|
||||
"section_scratch.ld",
|
||||
"sections_default.ld",
|
||||
"sections_no_flash.ld",
|
||||
"set_memory_locations.ld",
|
||||
"rp2_common/memmap_default.ld",
|
||||
"rp2_common/memmap_no_flash.ld",
|
||||
"rp2_common/memmap_copy_to_ram.ld",
|
||||
]
|
||||
)
|
||||
|
||||
include_linker_script_dir(
|
||||
name = "rp2_linker_script_args",
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "rp2_linker_scripts",
|
||||
target_compatible_with = compatible_with_rp2(),
|
||||
deps = [
|
||||
"rp2_linker_script_args",
|
||||
"memory_aliases_default.ld",
|
||||
"memory_aliases_no_flash.ld",
|
||||
"memory_flash.ld",
|
||||
"memory_ram.ld",
|
||||
"memory_scratch.ld",
|
||||
"memory_xip_ram.ld",
|
||||
"section_copy_to_ram_data.ld",
|
||||
"section_default_data.ld",
|
||||
"section_end.ld",
|
||||
"section_flash_end.ld",
|
||||
"section_heap.ld",
|
||||
"section_no_flash_data.ld",
|
||||
"sections_copy_to_ram.ld",
|
||||
"section_scratch.ld",
|
||||
"sections_default.ld",
|
||||
"sections_no_flash.ld",
|
||||
"set_memory_locations.ld",
|
||||
"rp2_common/memmap_default.ld",
|
||||
"rp2_common/memmap_no_flash.ld",
|
||||
"rp2_common/memmap_copy_to_ram.ld",
|
||||
],
|
||||
)
|
||||
Loading…
Add table
Reference in a new issue