Skip to content

Commit 5c2f7ca

Browse files
authored
feat: RiscV64 support (#1091)
* RiscV64 support * Chore Cleanup RV64gc * FIx a minor typo
1 parent d16d75f commit 5c2f7ca

12 files changed

Lines changed: 147 additions & 91 deletions

File tree

apk/apk.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,20 @@ func init() {
6161
// https://github.com/golang/go/blob/master/src/internal/syslist/syslist.go
6262
// nolint: gochecknoglobals
6363
var archToAlpine = map[string]string{
64-
"all": "noarch",
65-
"386": "x86",
66-
"amd64": "x86_64",
67-
"arm64": "aarch64",
68-
"arm6": "armhf",
69-
"arm7": "armv7",
70-
"ppc64le": "ppc64le",
71-
"s390": "s390x",
72-
"loong64": "loongarch64",
73-
"aarch64": "aarch64",
74-
"x86_64": "x86_64",
75-
"i386": "x86",
76-
"i686": "x86",
64+
"all": "noarch",
65+
"386": "x86",
66+
"amd64": "x86_64",
67+
"arm64": "aarch64",
68+
"arm6": "armhf",
69+
"arm7": "armv7",
70+
"ppc64le": "ppc64le",
71+
"s390": "s390x",
72+
"loong64": "loongarch64",
73+
"aarch64": "aarch64",
74+
"x86_64": "x86_64",
75+
"i386": "x86",
76+
"i686": "x86",
77+
"riscv64": "riscv64",
7778
}
7879

7980
func ensureValidArch(info *nfpm.Info) *nfpm.Info {

apk/apk_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func TestDefaultWithArch(t *testing.T) {
138138
"etc/fake/fake2.conf": "96c335dc28122b5f09a4cef74b156cd24c23784c",
139139
"etc/fake/fake3.conf": "96c335dc28122b5f09a4cef74b156cd24c23784c",
140140
}
141-
for _, arch := range []string{"386", "amd64"} {
141+
for _, arch := range []string{"386", "amd64", "riscv64"} {
142142
t.Run(arch, func(t *testing.T) {
143143
info := exampleInfo()
144144
info.Arch = arch

arch/arch.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@ type ArchLinux struct{}
4242

4343
// nolint: gochecknoglobals
4444
var archToArchLinux = map[string]string{
45-
"all": "any",
46-
"amd64": "x86_64",
47-
"386": "i686",
48-
"arm64": "aarch64",
49-
"arm7": "armv7h",
50-
"arm6": "armv6h",
51-
"arm5": "arm",
52-
"x86_64": "x86_64",
53-
"aarch64": "aarch64",
54-
"i386": "i686",
45+
"all": "any",
46+
"amd64": "x86_64",
47+
"386": "i686",
48+
"arm64": "aarch64",
49+
"arm7": "armv7h",
50+
"arm6": "armv6h",
51+
"arm5": "arm",
52+
"x86_64": "x86_64",
53+
"aarch64": "aarch64",
54+
"i386": "i686",
55+
"riscv64": "riscv64",
5556
}
5657

5758
func ensureValidArch(info *nfpm.Info) *nfpm.Info {

arch/arch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestConventionalExtension(t *testing.T) {
9494
}
9595

9696
func TestArch(t *testing.T) {
97-
for _, arch := range []string{"386", "amd64", "arm64"} {
97+
for _, arch := range []string{"386", "amd64", "arm64", "riscv64"} {
9898
t.Run(arch, func(t *testing.T) {
9999
info := exampleInfo()
100100
info.Arch = arch
@@ -129,7 +129,7 @@ func TestArchNoInfo(t *testing.T) {
129129
}
130130

131131
func TestArchConventionalFileName(t *testing.T) {
132-
for _, arch := range []string{"386", "amd64", "arm64"} {
132+
for _, arch := range []string{"386", "amd64", "arm64", "riscv64"} {
133133
t.Run(arch, func(t *testing.T) {
134134
info := exampleInfo()
135135
info.Arch = arch

deb/deb.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,18 @@ func init() {
4343
// https://wiki.debian.org/ArchitectureSpecificsMemo
4444
// nolint: gochecknoglobals
4545
var archToDebian = map[string]string{
46-
"386": "i386",
47-
"arm64": "arm64",
48-
"arm5": "armel",
49-
"arm6": "armhf",
50-
"arm7": "armhf",
51-
"mips64le": "mips64el",
52-
"mipsle": "mipsel",
53-
"ppc64le": "ppc64el",
54-
"s390": "s390x",
55-
"x86_64": "amd64",
56-
"aarch64": "arm64",
46+
"386": "i386",
47+
"arm64": "arm64",
48+
"arm5": "armel",
49+
"arm6": "armhf",
50+
"arm7": "armhf",
51+
"mips64le": "mips64el",
52+
"mipsle": "mipsel",
53+
"ppc64le": "ppc64el",
54+
"s390": "s390x",
55+
"x86_64": "amd64",
56+
"aarch64": "arm64",
57+
"riscv64": "riscv64",
5758
}
5859

5960
func ensureValidArch(info *nfpm.Info) *nfpm.Info {

deb/deb_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestConventionalExtension(t *testing.T) {
111111
}
112112

113113
func TestDeb(t *testing.T) {
114-
for _, arch := range []string{"386", "amd64"} {
114+
for _, arch := range []string{"386", "amd64", "riscv64"} {
115115
t.Run(arch, func(t *testing.T) {
116116
info := exampleInfo()
117117
info.Arch = arch

ipk/ipk.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ func init() {
3232
// nolint: gochecknoglobals
3333
var archToIPK = map[string]string{
3434
// all --> all
35-
"386": "i386",
36-
"amd64": "x86_64",
37-
"arm64": "arm64",
38-
"arm5": "armel",
39-
"arm6": "armhf",
40-
"arm7": "armhf",
41-
"mips64le": "mips64el",
42-
"mipsle": "mipsel",
43-
"ppc64le": "ppc64el",
44-
"s390": "s390x",
45-
"x86_64": "x86_64",
46-
"aarch64": "arm64",
47-
"i386": "i386",
35+
"386": "i386",
36+
"amd64": "x86_64",
37+
"arm64": "arm64",
38+
"arm5": "armel",
39+
"arm6": "armhf",
40+
"arm7": "armhf",
41+
"mips64le": "mips64el",
42+
"mipsle": "mipsel",
43+
"ppc64le": "ppc64el",
44+
"s390": "s390x",
45+
"x86_64": "x86_64",
46+
"aarch64": "arm64",
47+
"i386": "i386",
48+
"riscv64": "riscv64_generic",
4849
}
4950

5051
func ensureValidArch(info *nfpm.Info) *nfpm.Info {

ipk/ipk_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestConventionalExtension(t *testing.T) {
9797
}
9898

9999
func TestIPK(t *testing.T) {
100-
for _, arch := range []string{"386", "amd64"} {
100+
for _, arch := range []string{"386", "amd64", "riscv64"} {
101101
t.Run(arch, func(t *testing.T) {
102102
info := exampleInfo()
103103
info.Arch = arch

rpm/rpm.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,18 @@ type RPM struct {
7777
// https://github.com/rpm-software-management/rpm/blob/4a9b7b5908d8b463a836b51322242677677bd8b7/lib/rpmrc.cc#L1167
7878
// nolint: gochecknoglobals
7979
var archToRPM = map[string]string{
80-
"all": "noarch",
81-
"amd64": "x86_64",
82-
"386": "i386",
83-
"arm64": "aarch64",
84-
"arm5": "armv5tel",
85-
"arm6": "armv6hl",
86-
"arm7": "armv7hl",
87-
"mips64le": "mips64el",
88-
"mipsle": "mipsel",
89-
"mips": "mips",
90-
"loong64": "loongarch64",
80+
"all": "noarch",
81+
"amd64": "x86_64",
82+
"386": "i386",
83+
"arm64": "aarch64",
84+
"arm5": "armv5tel",
85+
"arm6": "armv6hl",
86+
"arm7": "armv7hl",
87+
"mips64le": "mips64el",
88+
"mipsle": "mipsel",
89+
"mips": "mips",
90+
"loong64": "loongarch64",
91+
"riscv64": "riscv64",
9192
}
9293

9394
func setDefaults(info *nfpm.Info) *nfpm.Info {

rpm/rpm_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,52 @@ func TestRPM(t *testing.T) {
154154
require.Equal(t, "Foo does things", description)
155155
}
156156

157+
func TestRPMRiscv64(t *testing.T) {
158+
f, err := os.CreateTemp(t.TempDir(), "test-riscv.rpm")
159+
require.NoError(t, err)
160+
info := exampleInfo()
161+
info.Arch = "riscv64"
162+
require.NoError(t, DefaultRPM.Package(info, f))
163+
164+
file, err := os.OpenFile(f.Name(), os.O_RDONLY, 0o600) //nolint:gosec
165+
require.NoError(t, err)
166+
defer func() {
167+
f.Close()
168+
file.Close()
169+
err = os.Remove(file.Name())
170+
require.NoError(t, err)
171+
}()
172+
rpm, err := rpmutils.ReadRpm(file)
173+
require.NoError(t, err)
174+
175+
arch, err := rpm.Header.GetString(rpmutils.ARCH)
176+
require.NoError(t, err)
177+
require.Equal(t, archToRPM["riscv64"], arch)
178+
}
179+
180+
func TestSRPMRiscv64(t *testing.T) {
181+
f, err := os.CreateTemp(t.TempDir(), "test-riscv.src.rpm")
182+
require.NoError(t, err)
183+
info := exampleInfo()
184+
info.Arch = "riscv64"
185+
require.NoError(t, DefaultSRPM.Package(info, f))
186+
187+
file, err := os.OpenFile(f.Name(), os.O_RDONLY, 0o600) //nolint:gosec
188+
require.NoError(t, err)
189+
defer func() {
190+
f.Close()
191+
file.Close()
192+
err = os.Remove(file.Name())
193+
require.NoError(t, err)
194+
}()
195+
rpm, err := rpmutils.ReadRpm(file)
196+
require.NoError(t, err)
197+
198+
arch, err := rpm.Header.GetString(rpmutils.ARCH)
199+
require.NoError(t, err)
200+
require.Equal(t, archToRPM["riscv64"], arch)
201+
}
202+
157203
func TestIssue952(t *testing.T) {
158204
info := exampleInfo()
159205
info.MTime = time.Time{}

0 commit comments

Comments
 (0)