Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions recipes-sdk/aws-greengrass-component-sdk/PATCHES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# aws-greengrass-component-sdk Patches

## Overview

These patches modify the upstream `aws-greengrass-component-sdk` Rust/C
hybrid library for cross-compilation under Yocto/OE. The SDK provides an
IPC interface for Greengrass components written in C, C++, and Rust.

Upstream repo: https://github.com/aws-greengrass/aws-greengrass-component-sdk

## Patch Analysis (as of upgrade 0.4.0 → 1.0.1)

### 0001-Add-bindgen-to-build.rs.patch
- **Purpose**: Adds `bindgen` as a build dependency and inserts bindgen
invocation into `rust/build.rs` to generate Rust FFI bindings (`c.rs`)
at build time from the C headers. Also adds a custom `timespec` struct
definition via `raw_line()` to avoid platform-dependent issues, and
blocklists the system `timespec` type.
- **Upstream-Status**: Pending
- **Status in v1.0.1**: MOSTLY UPSTREAMED. v1.0.1 already includes bindgen
in `Cargo.toml` and has its own bindgen invocation in `build.rs`. However,
the upstream version does NOT include the `timespec` blocklist/raw_line
workaround or the `GG_OBJ_NULL` raw_line. The patch's Hunk #1
(Cargo.toml) is now a no-op. Hunk #2 (build.rs) FAILS because upstream
restructured `build.rs` significantly (dual layout support, different
variable names).
- **Action needed**: Regenerate. Only the `timespec`-related raw_lines and
blocklist are still needed (if patch 0002 is still needed). The bindgen
invocation itself is now upstream.

### 0002-Fix-timespec-types-for-32-bit-platforms.patch
- **Purpose**: Fixes `rust/src/ipc.rs` to use `c_long` instead of `i64` for
`timespec` fields (`tv_sec`, `tv_nsec`). On 32-bit ARM, `c_long` is 32
bits while `i64` is 64 bits, causing struct layout mismatch with the C
`timespec`.
- **Upstream-Status**: Pending
- **Applied only on**: `arm` (32-bit) via `SRC_URI:append:arm`
- **Status in v1.0.1**: STILL NEEDED. v1.0.1 still uses `i64` casts:
`tv_sec: d.as_secs() as i64` and `tv_nsec: i64::from(d.subsec_nanos())`.
- **Action needed**: May need context refresh if surrounding code changed,
but the fix itself is still required for 32-bit ARM.

### 0003-Build-gg-sdk-as-cdylib.patch
- **Purpose**: Adds `[lib] crate-type = ["cdylib", "rlib"]` to
`rust/Cargo.toml` so the Rust library builds as both a C-compatible
shared library (`libgg_sdk.so`) and a Rust static library (`.rlib`).
Without this, only an rlib is produced and C consumers can't link it.
- **Upstream-Status**: Inappropriate [Yocto-specific]
- **Status in v1.0.1**: PARTIALLY UPSTREAMED. v1.0.1 has `[lib]` with
`name = "gg_sdk"` but does NOT include `crate-type = ["cdylib", "rlib"]`.
- **Action needed**: Regenerate. The patch currently inserts `[lib]` before
`[build-dependencies]`, but v1.0.1 already has a `[lib]` section. Needs
to add `crate-type` to the existing `[lib]` section instead.

### 0004-Update-Cargo.lock-for-bindgen.patch
- **Purpose**: Adds all bindgen transitive dependencies to `rust/Cargo.lock`
so that the Yocto cargo fetcher can download them. Without this, the lock
file doesn't know about bindgen's dependency tree.
- **Upstream-Status**: Submitted (PR #91)
- **Status in v1.0.1**: UPSTREAMED. v1.0.1's `Cargo.lock` already includes
bindgen and all its dependencies.
- **Action needed**: DROP. This patch is no longer needed.

### 0005-Disable-strip-in-Cargo-profile.patch
- **Purpose**: Removes `strip = true` from `[profile.release]` in
`rust/Cargo.toml` so that Yocto's own stripping mechanism handles debug
symbol removal instead of Cargo doing it during compilation.
- **Upstream-Status**: Inappropriate [Yocto-specific]
- **Status in v1.0.1**: STILL NEEDED. v1.0.1 still has `strip = true`.
- **Action needed**: Context refresh may be needed if Cargo.toml layout
changed, but the fix itself is still required.

## Summary for v1.0.1

| Patch | Needed? | Action |
|-------|---------|--------|
| 0001 (bindgen in build.rs) | Partially | Regenerate — only timespec workaround needed |
| 0002 (32-bit timespec fix) | Yes (arm only) | Verify context, likely applies cleanly |
| 0003 (cdylib crate-type) | Yes | Regenerate for new Cargo.toml layout |
| 0004 (Cargo.lock update) | No | Drop — upstreamed in v1.0.1 |
| 0005 (disable strip) | Yes | Verify context, likely applies cleanly |
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SRC_URI += " \
crate://crates.io/find-msvc-tools/0.1.4 \
crate://crates.io/glob/0.3.3 \
crate://crates.io/itertools/0.13.0 \
crate://crates.io/libc/0.2.177 \
crate://crates.io/libc/0.2.181 \
crate://crates.io/libloading/0.8.9 \
crate://crates.io/log/0.4.28 \
crate://crates.io/memchr/2.7.6 \
Expand Down Expand Up @@ -43,7 +43,7 @@ SRC_URI[either-1.15.0.sha256sum] = "48c757948c5ede0e46177b7add2e67155f70e33c07fe
SRC_URI[find-msvc-tools-0.1.4.sha256sum] = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
SRC_URI[glob-0.3.3.sha256sum] = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
SRC_URI[itertools-0.13.0.sha256sum] = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
SRC_URI[libc-0.2.177.sha256sum] = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
SRC_URI[libc-0.2.181.sha256sum] = "459427e2af2b9c839b132acb702a1c654d95e10f8c326bfc2ad11310e458b1c5"
SRC_URI[libloading-0.8.9.sha256sum] = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
SRC_URI[log-0.4.28.sha256sum] = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
SRC_URI[memchr-2.7.6.sha256sum] = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ HOMEPAGE = "https://github.com/aws-greengrass/aws-greengrass-component-sdk"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=34400b68072d710fecd0a2940a0d1658"

PV = "0.4.0+git${SRCPV}"
PV = "1.0.1"

SRCREV = "4ee9ad4ef5ae5a190a5076e7a823510f9ee2a433"
SRCREV = "1e2495b4e7a616d35b374bba4635a95dbb678b95"
SRC_URI = "git://github.com/aws-greengrass/aws-greengrass-component-sdk.git;protocol=https;branch=main \
file://0001-Add-bindgen-to-build.rs.patch \
file://0003-Build-gg-sdk-as-cdylib.patch \
file://0004-Update-Cargo.lock-for-bindgen.patch \
file://0005-Disable-strip-in-Cargo-profile.patch \
file://0001-Add-timespec-blocklist-and-portable-struct-for-cross.patch \
file://0003-Build-gg-sdk-as-cdylib-for-shared-library-support.patch \
file://0004-Disable-strip-in-Cargo-profile.patch \
"

# nooelint: oelint.vars.specific
Expand Down Expand Up @@ -133,7 +132,7 @@ do_install() {
fi

# Install C static library
install -m 0644 ${B}/target/${CARGO_TARGET_SUBDIR}/build/gg-sdk-*/out/libgg-sdk.a ${D}${libdir}/
install -m 0644 ${B}/target/${CARGO_TARGET_SUBDIR}/build/aws-greengrass-component-sdk-*/out/libgg-sdk.a ${D}${libdir}/

# Install headers
install -d ${D}${includedir}/gg
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
From 50faa52900cb9e49767178eaae84248409a7a80c Mon Sep 17 00:00:00 2001
From: Richard Elberger <elberger@amazon.com>
Date: Thu, 9 Apr 2026 14:40:46 -0400
Subject: [PATCH 1/4] Add timespec blocklist and portable struct for
cross-compilation

Blocklist the system timespec type from bindgen and provide a
portable definition using c_long, which is correct on both 32-bit
and 64-bit platforms. Also add GG_OBJ_NULL constant and disable
layout tests which fail during cross-compilation.

Upstream-Status: Pending
---
rust/build.rs | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/rust/build.rs b/rust/build.rs
index 5297a1d..0dbc5a7 100644
--- a/rust/build.rs
+++ b/rust/build.rs
@@ -55,11 +55,18 @@ fn main() {
.allowlist_type("Gg.*")
.allowlist_type("GgIpc.*")
.allowlist_var("GG_.*")
+ .blocklist_type("timespec")
.raw_line("#![allow(non_upper_case_globals)]")
.raw_line("#![allow(non_camel_case_types)]")
.raw_line("#![allow(non_snake_case)]")
.raw_line("#![allow(dead_code)]")
.raw_line("#![allow(clippy::pedantic)]")
+ .raw_line("use core::ffi::c_long;")
+ .raw_line("#[repr(C)]")
+ .raw_line("#[derive(Debug, Copy, Clone, Default)]")
+ .raw_line("pub struct timespec { pub tv_sec: c_long, pub tv_nsec: c_long }")
+ .raw_line("pub const GG_OBJ_NULL: GgObject = unsafe { core::mem::zeroed() };")
+ .layout_tests(false)
.generate()
.unwrap()
.write_to_file(manifest_dir.join("src/c.rs"))
--
2.43.0

Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
From ccd16ebc966033f538b1174047ca21b7f943d65c Mon Sep 17 00:00:00 2001
From: Richard Elberger <elberger@amazon.com>
Date: Thu, 9 Apr 2026 14:41:43 -0400
Subject: [PATCH 2/4] Fix timespec types for 32-bit platforms

Use c_long instead of i64 for timespec fields. On 32-bit ARM,
c_long is 32 bits while i64 is 64 bits, causing struct layout
mismatch with the C timespec.

Upstream-Status: Pending
---
rust/src/ipc.rs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

Index: aws-greengrass-component-sdk-0.4.0/rust/src/ipc.rs
===================================================================
--- aws-greengrass-component-sdk-0.4.0.orig/rust/src/ipc.rs
+++ aws-greengrass-component-sdk-0.4.0/rust/src/ipc.rs
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
diff --git a/rust/src/ipc.rs b/rust/src/ipc.rs
index 4056fbb..42366ea 100644
--- a/rust/src/ipc.rs
+++ b/rust/src/ipc.rs
@@ -486,8 +486,8 @@ impl Sdk {

use std::{
- env, ffi,
+ env, ffi::{self, c_long},
marker::PhantomData,
mem, ptr, result, slice, str,
sync::{Mutex, OnceLock},
@@ -548,8 +548,8 @@ impl Ipc {
t.duration_since(std::time::UNIX_EPOCH).unwrap_or_default();
#[expect(clippy::cast_possible_wrap)]
c::timespec {
- tv_sec: duration.as_secs() as i64,
- tv_nsec: i64::from(duration.subsec_nanos()),
+ tv_sec: duration.as_secs() as c_long,
+ tv_nsec: duration.subsec_nanos() as c_long,
}
});
let timespec = timestamp.map(|d| c::timespec {
- tv_sec: d.as_secs() as i64,
- tv_nsec: i64::from(d.subsec_nanos()),
+ tv_sec: d.as_secs() as ffi::c_long,
+ tv_nsec: d.subsec_nanos() as ffi::c_long,
});

Result::from(unsafe {
--
2.43.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
From 747efdccb2f1f6aa40c7dcbc94dd060cb63f3902 Mon Sep 17 00:00:00 2001
From: Richard Elberger <elberger@amazon.com>
Date: Thu, 9 Apr 2026 14:42:05 -0400
Subject: [PATCH 3/4] Build gg-sdk as cdylib for shared library support

Add crate-type cdylib so the Rust library produces a C-compatible
shared library (libgg_sdk.so) in addition to the rlib.

Since the crate is no_std, a cdylib target requires a panic_handler.
Add one that aborts on panic, matching the upstream Cargo.toml
profile.release panic = "abort" setting.

Upstream-Status: Inappropriate [Yocto-specific]
---
rust/Cargo.toml | 1 +
rust/src/lib.rs | 6 ++++++
2 files changed, 7 insertions(+)

diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index c8d2bb9..31a472e 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -21,6 +21,7 @@ include = [

[lib]
name = "gg_sdk"
+crate-type = ["cdylib", "rlib"]

[build-dependencies]
bindgen = "0.72.1"
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 42fc8ef..53e52b4 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -8,6 +8,12 @@
#![warn(missing_docs, clippy::pedantic, clippy::cargo)]
#![allow(clippy::enum_glob_use)]

+#[cfg(not(test))]
+#[panic_handler]
+fn panic(_info: &core::panic::PanicInfo) -> ! {
+ loop {}
+}
+
#[cfg(test)]
extern crate std;

--
2.43.0

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From c526d08ac614253af1a4cecf0e9d8f0d18a749a4 Mon Sep 17 00:00:00 2001
From: Richard Elberger <elberger@amazon.com>
Date: Thu, 9 Apr 2026 14:42:33 -0400
Subject: [PATCH 4/4] Disable strip in Cargo profile

Let Yocto handle stripping instead of Cargo doing it during
compilation.

Upstream-Status: Inappropriate [Yocto-specific]
---
rust/Cargo.toml | 1 -
1 file changed, 1 deletion(-)

diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 31a472e..dead60b 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -28,7 +28,6 @@ bindgen = "0.72.1"
cc = "1"

[profile.release]
-strip = true
opt-level = "z"
lto = true
codegen-units = 1
--
2.43.0

Loading
Loading