Skip to content
This repository was archived by the owner on May 22, 2023. It is now read-only.

Commit 94e52c0

Browse files
committed
Build ARM elf with libcomponent
ref #97
1 parent 555a760 commit 94e52c0

File tree

7 files changed

+108
-1
lines changed

7 files changed

+108
-1
lines changed

cement

+37
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,43 @@ def get_component_files(xml_file):
9494
return (set([c_tag.get("implementation") for c_tag in ET.parse(xml_file).getroot().findall("component")]))
9595

9696
def gpr_compile(config, gneiss_root, build_dir, root_dir, paths, platform, logger, verbose):
97+
if platform == "nRF52832":
98+
gpr_compile_nrf52832(config, gneiss_root, build_dir, paths, platform, logger, verbose)
99+
else:
100+
gpr_compile_linux(config, gneiss_root, build_dir, root_dir, paths, platform, logger, verbose)
101+
102+
def gpr_compile_nrf52832(config, gneiss_root, build_dir, paths, platform, logger, verbose):
103+
logger.info("Creating project...")
104+
project_dir = os.path.join(build_dir, "nRF52832")
105+
try:
106+
os.mkdir(build_dir)
107+
os.mkdir(project_dir)
108+
except FileExistsError:
109+
pass
110+
args = ["-p",
111+
"-P", "core",
112+
"-XGNEISS_PLATFORM=" + platform,
113+
"-XGCC_VERSION=" + get_gcc_version(),
114+
"-XGNEISS_ROOT=" + gneiss_root,
115+
"-XCEMENT_OBJECT_DIR=" + os.path.join(project_dir, "obj/"),
116+
"-XCEMENT_LIB_OBJECT_DIR=" + os.path.join(project_dir, "libobj/"),
117+
"-XCEMENT_LIBRARY_DIR=" + os.path.join(project_dir, "lib/"),
118+
"-XCEMENT_COMPONENT_DIR=" + os.path.join(project_dir, "libcomponents/"),
119+
"--db", os.path.join(gneiss_root, "gprconfig_db"),
120+
"-aP", project_dir]
121+
for p in paths:
122+
args.extend(["-aP", p])
123+
with open(os.path.join(project_dir, "core.gpr"), "w") as core_gpr:
124+
core_gpr.write("\n".join([f"with \"{c}\";" for c in get_component_files(config)]))
125+
core_gpr.write("\n\n")
126+
with open(os.path.join(gneiss_root, f"src/core/{platform}/core.gpr"), "r") as core_template:
127+
core_gpr.write(core_template.read())
128+
for step in ["prepare", "compile"]:
129+
args += ["-XCEMENT_BUILD_STEP=" + step]
130+
logger.debug("gprbuild " + " ".join(args))
131+
gprbuild(args)
132+
133+
def gpr_compile_linux(config, gneiss_root, build_dir, root_dir, paths, platform, logger, verbose):
97134
logger.info("Compiling...")
98135
components = get_component_files(config)
99136
logger.info("Preparing init...")

src/core/nRF52832/core.gpr

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ project Core is
3535
end Compiler;
3636

3737
package Linker is
38-
for Default_Switches ("Ada") use ("-Wl,--gc-sections", "-Wl,--print-memory-usage", "-T", "link.ld");
38+
for Default_Switches ("Ada") use ("-Wl,--gc-sections", "-Wl,--print-memory-usage", "-T",
39+
Gneiss_Root & "/src/core/nRF52832/link.ld");
3940
end Linker;
4041

4142
package Binder is

test/empty.gpr

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
project Empty extends "gneiss_component" is
3+
4+
Src_Dirs := ("empty");
5+
6+
case Build_Step is
7+
when "compile" =>
8+
for Runtime ("Ada") use Gneiss_Runtime;
9+
for Source_Dirs use Src_Dirs;
10+
for Object_Dir use external ("CEMENT_OBJECT_DIR");
11+
for Library_Name use Gneiss_Component_Prefix & "empty";
12+
case Platform is
13+
when "nRF52832" =>
14+
for Library_Kind use "static";
15+
when others =>
16+
for Library_Kind use "dynamic";
17+
for Library_Standalone use "encapsulated";
18+
for Library_Interface use ("component");
19+
end case;
20+
for Library_Dir use external ("CEMENT_COMPONENT_DIR");
21+
when others =>
22+
for Languages use ();
23+
end case;
24+
25+
end Empty;

test/empty/empty-component.adb

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
package body Empty.Component with
3+
SPARK_Mode
4+
is
5+
6+
I : Integer;
7+
8+
procedure Construct (Capability : Gneiss.Capability)
9+
is
10+
begin
11+
null;
12+
end Construct;
13+
14+
procedure Destruct
15+
is
16+
begin
17+
null;
18+
end Destruct;
19+
20+
begin
21+
I := 42;
22+
end Empty.Component;

test/empty/empty-component.ads

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
with Gneiss;
3+
with Gneiss.Component;
4+
5+
package Empty.Component with
6+
SPARK_Mode
7+
is
8+
9+
procedure Construct (Capability : Gneiss.Capability);
10+
11+
procedure Destruct;
12+
13+
package Main is new Gneiss.Component (Construct, Destruct);
14+
15+
end Empty.Component;

test/empty/empty.ads

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
package Empty is
3+
4+
end Empty;

test/empty/empty.xml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<config>
2+
<component name="empty" implementation="empty"/>
3+
</config>

0 commit comments

Comments
 (0)