Skip to content

Commit 658cc25

Browse files
authored
Merge pull request #337 from 0xsequence/fix-build-rust-library
Fixed errors when packaging the plugin's rust library for target platforms
2 parents baf4568 + f3623b1 commit 658cc25

File tree

9 files changed

+85
-10
lines changed

9 files changed

+85
-10
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Config/EosConfig.ini
3434
*.lai
3535
*.la
3636
*.a
37-
*.lib
3837

3938
# Executables
4039
*.exe

Plugins/SequencePlugin/Source/SequencePlugin/Private/Sequence/SequencePay.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void USequencePay::GetSwapPrice(const int64 ChainID, const FString& WalletAddres
9797
{
9898
this->GetSwapPrices(ChainID, WalletAddress, BuyCurrency, BuyAmount, [SellCurrency, OnSuccess, OnFailure](TArray<FSeqSwapPrice> Prices)
9999
{
100-
for (const FSeqSwapPrice Price : Prices)
100+
for (const FSeqSwapPrice& Price : Prices)
101101
{
102102
if (Price.CurrencyAddress == SellCurrency)
103103
{
@@ -139,7 +139,10 @@ void USequencePay::GetSwapPrices(const int64 ChainID, const FString& WalletAddre
139139

140140
for (const FSeqSwapToken& FromToken : Route.FromTokens)
141141
{
142-
SwapPrices.Add(FSeqSwapPrice(FromToken.Address, FromToken.Price));
142+
SwapPrices.Add(FSeqSwapPrice {
143+
FromToken.Address,
144+
FromToken.Price
145+
});
143146
}
144147
}
145148

Plugins/SequencePlugin/Source/SequencePlugin/Public/EthAbi/README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Run the installation steps from the official website:
1212

1313
https://doc.rust-lang.org/cargo/getting-started/installation.html
1414

15-
## Updating Library
15+
## Compiling Library
1616

1717
Navigate to the `SequencePlugin/Source/SequencePlugin/Public/EthAbi/` directory in your terminal and run the following code to compile:
1818

@@ -22,6 +22,52 @@ cargo build --release
2222

2323
Now, take the `libethabi_bridge.a` file from the `./target/release/` directory and move it to `EthAbi/`
2424

25+
## Platforms Builds
26+
27+
MacOS, iOS and Android files can be build on MacOS and Windows. Windows' .lib file can only be installed on a Windows machine.
28+
29+
### MacOS
30+
31+
```shell
32+
cargo build --release --target x86_64-apple-darwin
33+
cargo build --release --target aarch64-apple-darwin
34+
```
35+
36+
```shell
37+
lipo -create \
38+
./target/x86_64-apple-darwin/release/libethabi_bridge.a \
39+
./target/aarch64-apple-darwin/release/libethabi_bridge.a \
40+
-output ./macos/libethabi_bridge.a
41+
```
42+
43+
### Android
44+
45+
```shell
46+
cargo ndk -t arm64-v8a -t armeabi-v7a -t x86_64 build --release
47+
```
48+
49+
### iOS
50+
51+
```shell
52+
cargo lipo --release
53+
```
54+
55+
### Windows
56+
57+
Building .lib files only works on Windows machines.
58+
Run the following install commands on Windows.
59+
60+
```shell
61+
winget install --id Rustlang.Rustup -e --source winget
62+
rustup default stable-x86_64-pc-windows-msvc
63+
```
64+
65+
Build command:
66+
67+
```shell
68+
cargo build --release --target x86_64-pc-windows-msvc
69+
```
70+
2571
## Decoding:
2672

2773
Returns JSON array as a string of unnamed values. This array mirrors the ABI's output array. E.g. [5000] or [[0,10000,1747809900,1905662700,"0x0000000000000000000000000000000000000000000000000000000000000000"]]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Plugins/SequencePlugin/Source/SequencePlugin/SequencePlugin.Build.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ public SequencePlugin(ReadOnlyTargetRules Target) : base(Target)
99
{
1010
bUseUnity = false;
1111
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
12-
13-
string lib = Path.Combine(PluginDirectory, "Source/SequencePlugin/Public/EthAbi/libethabi_bridge.a");
14-
string includes = Path.Combine(ModuleDirectory, "Public/EthAbi/");
1512

16-
PublicSystemLibraryPaths.Add(includes);
17-
PublicAdditionalLibraries.Add(lib);
18-
13+
AddEthAbiLibraries();
14+
1915
PublicIncludePaths.AddRange(
2016
new string[] {
2117
// ... add public include paths required here ...
@@ -141,4 +137,35 @@ public SequencePlugin(ReadOnlyTargetRules Target) : base(Target)
141137
);//Public Frameworks
142138
}//IOS Frameworks
143139
}//SequencePlugin
140+
141+
public void AddEthAbiLibraries()
142+
{
143+
string EthAbiDirectory = Path.Combine(PluginDirectory, "Source/SequencePlugin/Public/EthAbi/");
144+
145+
PublicSystemLibraryPaths.Add(EthAbiDirectory);
146+
147+
if (Target.Platform == UnrealTargetPlatform.Win64)
148+
{
149+
string libDir = Path.Combine(EthAbiDirectory, "windows");
150+
PublicAdditionalLibraries.Add(Path.Combine(libDir, "libethabi_bridge.lib"));
151+
152+
// Add extra MSVC libs here
153+
// PublicSystemLibraries.AddRange(new string[] { "advapi32", "bcrypt" });
154+
}
155+
else if (Target.Platform == UnrealTargetPlatform.Mac)
156+
{
157+
string libDir = Path.Combine(EthAbiDirectory, "macos");
158+
PublicAdditionalLibraries.Add(Path.Combine(libDir, "libethabi_bridge.a"));
159+
}
160+
else if (Target.Platform == UnrealTargetPlatform.IOS)
161+
{
162+
PublicAdditionalLibraries.Add(Path.Combine(EthAbiDirectory, "ios", "libethabi_bridge.a"));
163+
}
164+
else if (Target.Platform == UnrealTargetPlatform.Android)
165+
{
166+
string libDir = Path.Combine(EthAbiDirectory, "android");
167+
PublicAdditionalLibraries.Add(Path.Combine(libDir, "arm64", "libethabi_bridge.a"));
168+
PublicAdditionalLibraries.Add(Path.Combine(libDir, "x86", "libethabi_bridge.a"));
169+
}
170+
}
144171
}//namespace

0 commit comments

Comments
 (0)