Skip to content

Commit 3e34315

Browse files
committed
Preliminary ARM support
1 parent 3b51880 commit 3e34315

File tree

5 files changed

+100
-46
lines changed

5 files changed

+100
-46
lines changed

.github/workflows/cmake-cross-compile.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: aarch64 builds
1+
name: ARM builds
22

33
on:
44
push:
@@ -46,13 +46,13 @@ jobs:
4646
run: sudo apt-get update && sudo apt-get install -y build-essential gcc g++ gdc ninja-build gdc-12-arm-linux-gnueabihf dub
4747

4848
- name: Configure CMake
49-
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Dbuild_sideloadipa=OFF -Dlink_libplist_dynamic=ON -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/toolchains/rpi-2.cmake -Dbuild_anisetteserver=OFF
49+
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Dbuild_sideloadipa=OFF -Dlink_libplist_dynamic=ON -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/toolchains/rpi-2.cmake
5050

5151
- name: Build
5252
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
5353

5454
- uses: actions/upload-artifact@v3
5555
with:
56-
name: retrieve-headers-armv7
56+
name: anisette-server-armv7
5757
path: |
58-
${{github.workspace}}/build/retrieve_headers
58+
${{github.workspace}}/build/anisette_server

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ if(build_anisetteserver)
9494
add_executable(anisette_server ${ANISETTE_SERVER_D_SOURCES})
9595
target_include_directories(anisette_server PUBLIC ${ANISETTE_SERVER_SOURCE_DIR})
9696

97-
target_link_libraries(anisette_server provision archttp)
97+
target_link_libraries(anisette_server provision handy-httpd)
9898
endif()

anisette_server/app.d

+58-40
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import archttp;
1+
import handy_httpd;
22
import std.algorithm.searching;
33
import std.array;
44
import std.base64;
@@ -7,10 +7,10 @@ import std.path;
77
import std.stdio;
88
import provision;
99

10-
void main(string[] args) {
11-
auto app = new Archttp;
12-
ADI* adi;
10+
__gshared static ADI* adi;
11+
__gshared static ulong rinfo;
1312

13+
void main(string[] args) {
1414
if (args.canFind("--remember-machine")) {
1515
adi = new ADI(expandTilde("~/.adi"));
1616
} else {
@@ -22,7 +22,6 @@ void main(string[] args) {
2222
adi = new ADI(expandTilde("~/.adi"), cast(char[]) id.toHexString().toLower());
2323
}
2424

25-
ulong rinfo;
2625
if (!adi.isMachineProvisioned()) {
2726
stderr.write("Machine requires provisioning... ");
2827
adi.provisionDevice(rinfo);
@@ -31,36 +30,37 @@ void main(string[] args) {
3130
adi.getRoutingInformation(rinfo);
3231
}
3332

34-
app.get("/reprovision", (req, res) {
35-
writefln!"[%s >>] GET /reprovision"(req.ip);
36-
adi.provisionDevice(rinfo);
37-
writefln!"[>> %s] 200 OK"(req.ip);
38-
res.code(HttpStatusCode.OK);
39-
});
40-
41-
app.get("/", (req, res) {
42-
try {
43-
import std.datetime.systime;
44-
import std.datetime.timezone;
45-
import core.time;
46-
auto time = Clock.currTime();
33+
auto serverConfig = ServerConfig.defaultValues;
34+
serverConfig.port = 6969;
35+
auto s = new HttpServer(simpleHandler((ref req, ref res) {
36+
if (req.url == "/reprovision") {
37+
writeln("[<<] GET /reprovision");
38+
adi.provisionDevice(rinfo);
39+
writeln("[>>] 200 OK");
40+
res.setStatus(200);
41+
} else {
42+
try {
43+
import std.datetime.systime;
44+
import std.datetime.timezone;
45+
import core.time;
46+
auto time = Clock.currTime();
4747

48-
writefln!"[%s >>] GET /"(req.ip);
48+
writefln("[<<] GET /");
4949

50-
ubyte[] mid;
51-
ubyte[] otp;
52-
try {
53-
adi.getOneTimePassword(mid, otp);
54-
} catch {
55-
writeln("Reprovision needed.");
56-
adi.provisionDevice(rinfo);
57-
adi.getOneTimePassword(mid, otp);
58-
}
50+
ubyte[] mid;
51+
ubyte[] otp;
52+
try {
53+
adi.getOneTimePassword(mid, otp);
54+
} catch (Throwable) {
55+
writeln("Reprovision needed.");
56+
adi.provisionDevice(rinfo);
57+
adi.getOneTimePassword(mid, otp);
58+
}
5959

60-
import std.conv;
61-
import std.json;
60+
import std.conv;
61+
import std.json;
6262

63-
JSONValue response = [
63+
JSONValue response = [
6464
"X-Apple-I-Client-Time": time.toISOExtString.split('.')[0] ~ "Z",
6565
"X-Apple-I-MD": Base64.encode(otp),
6666
"X-Apple-I-MD-M": Base64.encode(mid),
@@ -71,18 +71,36 @@ void main(string[] args) {
7171
"X-Apple-I-TimeZone": time.timezone.dstName,
7272
"X-Apple-Locale": "en_US",
7373
"X-Mme-Device-Id": adi.deviceId,
74-
];
74+
];
7575

76-
writefln!"[>> %s] 200 OK %s"(req.ip, response);
76+
writefln!"[>>] 200 OK %s"(response);
7777

78-
res.code(HttpStatusCode.OK);
79-
res.send(response);
80-
} catch(Throwable t) {
81-
res.code(HttpStatusCode.INTERNAL_SERVER_ERROR);
82-
res.send(t.toString());
78+
res.setStatus(200);
79+
res.writeBody(to!string(response));
80+
} catch(Throwable t) {
81+
res.setStatus(500);
82+
res.writeBody(t.toString());
83+
}
8384
}
84-
});
85+
}), serverConfig);
86+
s.start();
87+
88+
/+
89+
90+
91+
92+
with (vib) {
93+
Get("/reprovision", (req, res) => "Hello World!");
94+
95+
Get("", (req, res) {
96+
});
97+
}
98+
99+
// listenHTTP is called automatically
100+
runApplication();
85101
86-
app.listen(6969);
102+
scope (exit)
103+
vib.Stop();
104+
// +/
87105
}
88106

cmake/dependencies.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ if(build_sideloadipa OR build_anisetteserver)
2424
endif()
2525

2626
if(build_anisetteserver)
27-
DubProject_Add(archttp ~1.1.0)
27+
DubProject_Add(handy-httpd ~3.2.0)
2828
endif()
2929
endif()

toolchains/rpi-2-no-suffix.cmake

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#File raspberrytoolchain.cmake for ROS and system packages to cross compile.
2+
SET(CMAKE_SYSTEM_NAME Linux)
3+
4+
SET(_CMAKE_TOOLCHAIN_PREFIX "arm-linux-gnueabihf-")
5+
6+
SET(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
7+
SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
8+
SET(CMAKE_D_COMPILER arm-linux-gnueabihf-gdc)
9+
10+
# Below call is necessary to avoid non-RT problem.
11+
SET(CMAKE_LIBRARY_ARCHITECTURE arm-linux-gnueabihf)
12+
13+
SET(RASPBERRY_ROOT_PATH /usr/arm-linux-gnueabihf/sys-root)
14+
SET(CMAKE_SYSROOT ${RASPBERRY_ROOT_PATH})
15+
16+
SET(CMAKE_FIND_ROOT_PATH ${RASPBERRY_ROOT_PATH})
17+
18+
#Have to set this one to BOTH, to allow CMake to find rospack
19+
#This set of variables controls whether the CMAKE_FIND_ROOT_PATH and CMAKE_SYSROOT are used for find_xxx() operations.
20+
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
21+
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
22+
# SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
23+
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
24+
25+
#If you have installed cross compiler to somewhere else, please specify that path.
26+
SET(COMPILER_ROOT ${RASPBERRY_ROOT_PATH})
27+
28+
SET(CMAKE_PREFIX_PATH ${RASPBERRY_ROOT_PATH})
29+
30+
SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -defaultlib=:libgphobos.a -fall-instantiations" CACHE INTERNAL "" FORCE)
31+
# SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${RASPBERRY_ROOT_PATH}" CACHE INTERNAL "" FORCE)
32+
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${RASPBERRY_ROOT_PATH}" CACHE INTERNAL "" FORCE)
33+
# SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --sysroot=${RASPBERRY_ROOT_PATH}" CACHE INTERNAL "" FORCE)
34+
# SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} --sysroot=${RASPBERRY_ROOT_PATH}" CACHE INTERNAL "" FORCE)
35+
36+
SET(LD_LIBRARY_PATH ${RASPBERRY_ROOT_PATH}/lib)

0 commit comments

Comments
 (0)