ARMmbed / mbed-client-for-aws

AWS IoT SDK port for Mbed OS
Apache License 2.0
8 stars 13 forks source link

Fix build on the Arm Compiler #4

Closed LDong-Arm closed 4 years ago

LDong-Arm commented 4 years ago

Part of the fix for https://github.com/ARMmbed/mbed-os-example-aws/issues/3 (Needs https://github.com/ARMmbed/mbed-os-example-aws/pull/7 too)

This PR addresses two issues that prevent the Arm Compiler from building mbed-os-example-aws.

Temporarily disable Defender module

The AWS SDK has a Defender module which requires the porting layer to implement IotClock_SleepMs, IotSemaphore_TryWait and IotMetrics_GetTcpConnections. For now we haven't provided those yet because mbed-os-example-aws doesn't use Defender at the moment.

Users can re-enable Defender by adding the missing implementation. Refer to the updated README.

Use ARMmbed/tinycbor repository for Arm Compiler compatibility

The upstream https://github.com/intel/tinycbor currently doesn't compile with the Arm Compiler:

The fork under ARMmbed has those issues resolved.

Note: Our fork has renamed cbor.h -> tinycbor.h, so we create cbor.h here to maintain compatibility with the AWS SDK.

Fix strftime() nullptr dereference with logging

Logging isn't properly enabled until we apply #3. Now with logging enabled, IotClock_GetTimestring() crashes because it uses gmtime() (which returns NULL due to the lack of support by the Arm Compiler's C library) in strftime().

The fix is using localtime() instead - it is also what the AWS SDK uses in its POSIX implementation.

LDong-Arm commented 4 years ago

@ithinuel @ashok-rao @evedon @MarceloSalazar This is one of the two PRs to fix the AWS example with the Arm Compiler, would you please have a look? Thanks. (I don't have permission to add reviewers.)

LDong-Arm commented 4 years ago

@ashok-rao I've updated README to include how to enable Defender.

LDong-Arm commented 4 years ago

@ithinuel @ashok-rao Just added another fix - we need to use localtime() instead of gmtime() (unsupported by the Arm Compiler). Also, local time is the time format used by AWS's official POSIX implementation...

evedon commented 4 years ago

Ready for merge @ithinuel ?

ithinuel commented 4 years ago

It still works for me with GCC. If @gpsimenos can confirm it does with ARMC6 I can merge this :)

LDong-Arm commented 4 years ago

@ithinuel Now we can merge it? Then I'll update the .lib in ARMmbed/mbed-os-example-aws#7