public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* Building C static Library for UEFI
@ 2022-07-30 14:25 Ayush Singh
  2022-08-09 18:32 ` [edk2-devel] " Andrew Fish
  0 siblings, 1 reply; 3+ messages in thread
From: Ayush Singh @ 2022-07-30 14:25 UTC (permalink / raw)
  To: edk2-devel-groups-io
  Cc: Mike Kinney, mikuback@linux.microsoft.com, Andrew Fish,
	Gaibusab, Jabeena B, Yao, Jiewen

[-- Attachment #1: Type: text/plain, Size: 1220 bytes --]

Hello everyone. There are some tests in Rust std that statically link to 
a C static library to check ffi. Since if Rust is ever used in edk2, it 
would probably have to integrate with the existing C code. Thus, I 
thought rather than ignoring these tests, I wanted to make them work.

What Rust cargo needs is a static C library (`.lib`) to link against. I 
was not really able to find much about linking in UEFI applications. 
However, from what I understand [1], edk2 already does do static link 
for C modules, so it should technically be the same for Rust as well as 
long as a static library can be generated from C code. I did look at the 
`build_rules` [2], but I don't know where the flags are defined. I think 
following rules: `C-Code-File` -> `Object-File` should technically 
create a static library, but would it work with projects outside edk2? 
Also, it would be great if someone can also help me with the flags that 
need to be supplied if it can.


Yours Sincerely

Ayush Singh


[1]: 
https://edk2-docs.gitbook.io/edk-ii-build-specification/9_build_or_make_stage/95_dynamic_link

[2]: 
https://github.com/tianocore/edk2/blob/e9150618ec91f79e70a1719ac8c198bee34a99be/BaseTools/Conf/build_rule.template

[-- Attachment #2: Type: text/html, Size: 1892 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] Building C static Library for UEFI
  2022-07-30 14:25 Building C static Library for UEFI Ayush Singh
@ 2022-08-09 18:32 ` Andrew Fish
  2022-08-10 14:18   ` Ayush Singh
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Fish @ 2022-08-09 18:32 UTC (permalink / raw)
  To: edk2-devel-groups-io, ayushdevel1325
  Cc: Mike Kinney, mikuback@linux.microsoft.com, Gaibusab, Jabeena B,
	Yao, Jiewen

[-- Attachment #1: Type: text/plain, Size: 2156 bytes --]

Did you figure this out?

The per compiler flags come from BaseTools/Conf/tools_def.template. When you do the edksetup.sh it gets copied to Conf/tools_def.ttxt and that is what the build uses. The rules to generate makefiles come from BaseTools/Conf/build_rule.template[2] and gets copied to Conf/build_rule.txt

You can override the generic compiler flags via a [BuildOptions] section in an INF [3] of DSC [4]. 

[1] https://github.com/tianocore/edk2/blob/master/BaseTools/Conf/tools_def.template
[2] https://github.com/tianocore/edk2/blob/master/BaseTools/Conf/build_rule.template
[3] https://github.com/tianocore/edk2/blob/master/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf#L28 
[4] https://github.com/tianocore/edk2/blob/master/OvmfPkg/OvmfPkgX64.dsc#L111


Thanks,

Andrew Fish


> On Jul 30, 2022, at 7:25 AM, Ayush Singh <ayushdevel1325@gmail.com> wrote:
> 
> Hello everyone. There are some tests in Rust std that statically link to a C static library to check ffi. Since if Rust is ever used in edk2, it would probably have to integrate with the existing C code. Thus, I thought rather than ignoring these tests, I wanted to make them work.
> 
> What Rust cargo needs is a static C library (`.lib`) to link against. I was not really able to find much about linking in UEFI applications. However, from what I understand [1], edk2 already does do static link for C modules, so it should technically be the same for Rust as well as long as a static library can be generated from C code. I did look at the `build_rules` [2], but I don't know where the flags are defined. I think following rules: `C-Code-File` -> `Object-File` should technically create a static library, but would it work with projects outside edk2? Also, it would be great if someone can also help me with the flags that need to be supplied if it can.
> 
> 
> 
> Yours Sincerely
> 
> Ayush Singh
> 
> 
> 
> [1]: https://edk2-docs.gitbook.io/edk-ii-build-specification/9_build_or_make_stage/95_dynamic_link
> 
> [2]: https://github.com/tianocore/edk2/blob/e9150618ec91f79e70a1719ac8c198bee34a99be/BaseTools/Conf/build_rule.template
> 
> 


[-- Attachment #2: Type: text/html, Size: 3649 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] Building C static Library for UEFI
  2022-08-09 18:32 ` [edk2-devel] " Andrew Fish
@ 2022-08-10 14:18   ` Ayush Singh
  0 siblings, 0 replies; 3+ messages in thread
From: Ayush Singh @ 2022-08-10 14:18 UTC (permalink / raw)
  To: Andrew Fish, edk2-devel-groups-io
  Cc: Mike Kinney, mikuback@linux.microsoft.com, Gaibusab, Jabeena B,
	Yao, Jiewen

[-- Attachment #1: Type: text/plain, Size: 2864 bytes --]

Hi Andrew. I did find out one solution that should work for Rust. The 
one I tried was number 3 [1]. Basically, you can use the native Windows 
target and it should be fine to link against. However, the C code I was 
trying to compile at that time (rust_test_helper), is not compatible 
with UEFI (uses some incompatible headers). I might write a version of 
`rust_test_helpers` for UEFI at some point, but it is not high priority 
right now.


Ayush Singh

[1]: 
https://doc.rust-lang.org/nightly/rustc/platform-support/unknown-uefi.html#cross-compilation-toolchains-and-c-code


On 8/10/22 00:02, Andrew Fish wrote:
> Did you figure this out?
>
> The per compiler flags come from BaseTools/Conf/tools_def.template. 
> When you do the edksetup.sh it gets copied to Conf/tools_def.ttxt and 
> that is what the build uses. The rules to generate makefiles come 
> from BaseTools/Conf/build_rule.template[2] and gets copied to 
> Conf/build_rule.txt
>
> You can override the generic compiler flags via a [BuildOptions] 
> section in an INF [3] of DSC [4].
>
> [1] 
> https://github.com/tianocore/edk2/blob/master/BaseTools/Conf/tools_def.template
> [2] 
> https://github.com/tianocore/edk2/blob/master/BaseTools/Conf/build_rule.template
> [3] 
> https://github.com/tianocore/edk2/blob/master/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf#L28 
>
> [4] 
> https://github.com/tianocore/edk2/blob/master/OvmfPkg/OvmfPkgX64.dsc#L111
>
>
> Thanks,
>
> Andrew Fish
>
>
>> On Jul 30, 2022, at 7:25 AM, Ayush Singh <ayushdevel1325@gmail.com> 
>> wrote:
>>
>> Hello everyone. There are some tests in Rust std that statically link 
>> to a C static library to check ffi. Since if Rust is ever used in 
>> edk2, it would probably have to integrate with the existing C code. 
>> Thus, I thought rather than ignoring these tests, I wanted to make 
>> them work.
>>
>> What Rust cargo needs is a static C library (`.lib`) to link against. 
>> I was not really able to find much about linking in UEFI 
>> applications. However, from what I understand [1], edk2 already does 
>> do static link for C modules, so it should technically be the same 
>> for Rust as well as long as a static library can be generated from C 
>> code. I did look at the `build_rules` [2], but I don't know where the 
>> flags are defined. I think following rules: `C-Code-File` -> 
>> `Object-File` should technically create a static library, but would 
>> it work with projects outside edk2? Also, it would be great if 
>> someone can also help me with the flags that need to be supplied if 
>> it can.
>>
>>
>> Yours Sincerely
>>
>> Ayush Singh
>>
>>
>> [1]: 
>> https://edk2-docs.gitbook.io/edk-ii-build-specification/9_build_or_make_stage/95_dynamic_link
>>
>> [2]: 
>> https://github.com/tianocore/edk2/blob/e9150618ec91f79e70a1719ac8c198bee34a99be/BaseTools/Conf/build_rule.template
>>
>> 
>

[-- Attachment #2: Type: text/html, Size: 6074 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-10 14:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-30 14:25 Building C static Library for UEFI Ayush Singh
2022-08-09 18:32 ` [edk2-devel] " Andrew Fish
2022-08-10 14:18   ` Ayush Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox